Remove compile warning messages
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_appinfo.c
index ad93c86..e88018f 100644 (file)
@@ -60,6 +60,7 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        const char *locale, uid_t uid, char **query, GList **bind_params)
 {
        int joined = 0;
+       int size;
        char *condition = NULL;
        char buf[MAX_QUERY_LEN] = { '\0' };
        char tmp_query[MAX_QUERY_LEN] = { '\0' };
@@ -110,11 +111,11 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        if (joined & E_PMINFO_APPINFO_JOIN_PRIVILEGE)
                strncat(tmp_query, join_privilege, sizeof(tmp_query) - strlen(tmp_query) - 1);
 
-       strncat(tmp_query, buf, sizeof(tmp_query) - strlen(tmp_query) - 1);
-
-       *query = strdup(tmp_query);
+       size = strlen(tmp_query) + strlen(buf) + 1;
+       *query = (char *)calloc(1, size);
        if (*query == NULL)
                return PMINFO_R_ERROR;
+       snprintf(*query, size, "%s%s", tmp_query, buf);
 
        return PMINFO_R_OK;
 }
@@ -786,8 +787,23 @@ static int _pkgmgrinfo_get_appinfo(const char *appid, uid_t uid,
        }
 
        info->app_info = (application_x *)g_hash_table_lookup(list, appid);
+       if (!info->app_info || !info->app_info->package) {
+               _LOGD("appinfo for [%s] is not existed for user [%d]",
+                               appid, uid);
+               g_hash_table_destroy(list);
+               free(locale);
+               free(info);
+               return PMINFO_R_ENOENT;
+       }
        info->locale = locale;
        info->package = strdup(info->app_info->package);
+       if (!info->package) {
+               _LOGE("out of memory");
+               g_hash_table_destroy(list);
+               free(locale);
+               free(info);
+               return PMINFO_R_ERROR;
+       }
 
        /* just free list only */
        g_hash_table_steal(list, (gconstpointer)appid);
@@ -3393,6 +3409,7 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
        char temp[PKG_STRING_LEN_MAX] = {'\0'};
        GSList *link = NULL;
        int prop = -1;
+       int ret;
        prop = _pminfo_appinfo_convert_to_prop_str(property);
        if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
                prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
@@ -3428,15 +3445,21 @@ API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
                        strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
                        _LOGI("Previous value is %s\n", prev);
                        filter->list = g_slist_delete_link(filter->list, link);
-                       snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
-                       strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
+                       ret = snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s,%s", prev, value);
+                       if (ret < 0 || ret > PKG_STRING_LEN_MAX - 1) {
+                               _LOGE("snprintf fail\n");
+                               free(node);
+                               free(val);
+                               return PMINFO_R_ERROR;
+                       }
+                       strncpy(val, temp, PKG_STRING_LEN_MAX);
                        _LOGI("New value is %s\n", val);
                        node->value = val;
                        filter->list = g_slist_append(filter->list, (gpointer)node);
                        memset(temp, '\0', PKG_STRING_LEN_MAX);
                } else {
                        snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s", value);
-                       strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
+                       strncpy(val, temp, PKG_STRING_LEN_MAX);
                        _LOGI("First value is %s\n", val);
                        node->value = val;
                        filter->list = g_slist_append(filter->list, (gpointer)node);