Check parameter 32/160932/2
authorhj kim <backto.kim@samsung.com>
Tue, 21 Nov 2017 00:01:17 +0000 (09:01 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 21 Nov 2017 00:05:27 +0000 (09:05 +0900)
Change-Id: I2b50b11bde42edccc094eb40abab7c831c1689ad

lib/media-util-user.c

index ff2ea0c..415feb1 100755 (executable)
@@ -59,17 +59,21 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
        int ret = MS_MEDIA_ERR_NONE;
        const char *result = NULL;
        struct tzplatform_context *context[128];
+       int idx = 0;
+
+       idx = uid - 5000;
+       MSAPI_RETVM_IF(idx < 0 || idx > 127, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid uid");
 
        g_mutex_lock(&tzplatform_mutex);
 
-       ret = tzplatform_context_create(&context[uid-5000]);
+       ret = tzplatform_context_create(&context[idx]);
        if (ret != 0) {
                MSAPI_DBG_ERR("Fail tzplatform_context_create");
                ret = MS_MEDIA_ERR_INTERNAL;
                goto ERROR;
        }
 
-       ret = tzplatform_context_set_user(context[uid-5000], uid);
+       ret = tzplatform_context_set_user(context[idx], uid);
        if (ret != 0) {
                MSAPI_DBG_ERR("Fail tzplatform_context_set_user");
                ret = MS_MEDIA_ERR_INTERNAL;
@@ -78,19 +82,19 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
 
        switch (type) {
        case MEDIA_DB:
-               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_DB, ".media.db");
+               result = tzplatform_context_mkpath(context[idx], TZ_USER_DB, ".media.db");
                break;
        case INTERNAL_ROOT:
-               result = tzplatform_context_getenv(context[uid-5000], TZ_USER_CONTENT);
+               result = tzplatform_context_getenv(context[idx], TZ_USER_CONTENT);
                break;
        case THUMB_ROOT:
-               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb");
+               result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb");
                break;
        case THUMB_INTERNAL:
-               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/phone");
+               result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb/phone");
                break;
        case THUMB_EXTERNAL:
-               result = tzplatform_context_mkpath(context[uid-5000], TZ_USER_SHARE, "media/.thumb/mmc");
+               result = tzplatform_context_mkpath(context[idx], TZ_USER_SHARE, "media/.thumb/mmc");
                break;
        default:
                MSAPI_DBG_ERR("Invalid type");
@@ -101,7 +105,7 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
        *path = g_strdup(result);
 
 ERROR:
-       tzplatform_context_destroy(context[uid-5000]);
+       tzplatform_context_destroy(context[idx]);
 
        g_mutex_unlock(&tzplatform_mutex);