if (outparam) {
if (version && version[0] != '\0') {
*outparam = g_strdup(version);
+ if (*outparam == NULL) {
+ SLOGE("Memory allocation error (%d): %m");
+ res = ISU_RES_ERR_INTERNAL;
+ }
} else {
*outparam = NULL;
}
prev->next = element;
}
prev = element;
+ if (element->name == NULL) {
+ SLOGE("Memory allocation error (%d): %m");
+ isu_list_free(*list);
+ *list = NULL;
+ res = ISU_RES_ERR_INTERNAL;
+ goto exit;
+ }
}
exit:
if (body != NULL) {
service_array = g_variant_get_strv(array, &len);
struct _isu_pkg_info *_pkg_info = malloc(sizeof(*_pkg_info));
if (_pkg_info == NULL) {
+ SLOGE("Memory allocation error (%d): %m");
res = ISU_RES_ERR_INTERNAL;
goto exit;
}
}
for (size_t i = 0; i < len; i++) {
_pkg_info->service_files[i] = strdup(service_array[i]);
+ if (_pkg_info->service_files[i] == NULL) {
+ SLOGE("Memory allocation error (%d): %m");
+ isu_pkg_info_free(_pkg_info);
+ res = ISU_RES_ERR_INTERNAL;
+ goto exit;
+ }
}
*pkg_info = _pkg_info;
return isu_dbus_call(DBUS_METHOD_INSTALL_DIR, path, NULL);
}
-int isu_version_compare_internal(const char *ver_a, const char *ver_b)
+isu_result isu_version_compare_internal(const char *ver_a, const char *ver_b, int *comp_result)
{
+ assert(ver_a);
+ assert(ver_b);
+ assert(comp_result);
+
__attribute__ ((__cleanup__(cleanup_char_ptr))) char *ver_a_copy = strdup(ver_a);
__attribute__ ((__cleanup__(cleanup_char_ptr))) char *ver_b_copy = strdup(ver_b);
+ if (ver_a_copy == NULL || ver_b_copy == NULL) {
+ *comp_result = 0;
+ return ISU_RES_ERR_INTERNAL;
+ }
+
const char delim[] = ".";
char *saveptr_a, *saveptr_b;
int num_b = token_b ? atoi(token_b) : 0;
if (num_a > num_b) {
- return 1;
+ *comp_result = 1;
+ return ISU_RES_OK;
} else if (num_a < num_b) {
- return -1;
+ *comp_result = -1;
+ return ISU_RES_OK;
}
token_a = strtok_r(NULL, delim, &saveptr_a);
token_b = strtok_r(NULL, delim, &saveptr_b);
}
- return 0;
+ *comp_result = 0;
+ return ISU_RES_OK;
}
isu_result isu_get_version_internal(const char *pkgId, char **version)
snprintf(buff, sizeof(buff), "%s/%s/isu.cfg", ISU_PKG_PATH, pkgId);
struct _isu_pkg_info *rw_pkg_info = get_pkg_info(buff);
+ bool bError = false;
if (ro_pkg_info == NULL) {
if (rw_pkg_info == NULL) {
*version = NULL;
} else {
*version = g_strdup(rw_pkg_info->version);
+ if (*version == NULL) {
+ bError = true;
+ }
}
} else {
if (rw_pkg_info == NULL) {
*version = g_strdup(ro_pkg_info->version);
+ if (*version == NULL) {
+ bError = true;
+ }
} else {
- if (isu_version_compare_internal(ro_pkg_info->version, rw_pkg_info->version) <= 0) {
+ int comp_res;
+ if (isu_version_compare_internal(ro_pkg_info->version, rw_pkg_info->version, &comp_res) != ISU_RES_OK) {
+ *version = NULL;
+ bError = true;
+ }
+ if (comp_res <= 0) {
*version = g_strdup(rw_pkg_info->version);
+ if (*version == NULL) {
+ bError = true;
+ }
} else {
*version = g_strdup(ro_pkg_info->version);
+ if (*version == NULL) {
+ bError = true;
+ }
}
}
}
isu_pkg_info_free(ro_pkg_info);
isu_pkg_info_free(rw_pkg_info);
- return *version ? ISU_RES_OK : ISU_RES_ERR_NOT_EXIST;
+ if (bError)
+ return ISU_RES_ERR_INTERNAL;
+ else
+ return *version ? ISU_RES_OK : ISU_RES_ERR_NOT_EXIST;
}
bool is_valid_isu_pkg(const char *path)