Add an exceptional handling 82/55282/3 accepted/tizen/mobile/20151223.052756 accepted/tizen/tv/20151223.052824 accepted/tizen/wearable/20151223.052845 submit/tizen/20151223.023412 submit/tizen_common/20151229.142028 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 23 Dec 2015 01:11:23 +0000 (10:11 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 23 Dec 2015 01:30:20 +0000 (10:30 +0900)
- If the argc is 1, the argv[1] is invalid access.

Change-Id: I38a50c8b950cb781649d84aaab77a82fe24b7e72
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/bundle.c

index 31e09d2..0da2fea 100644 (file)
@@ -843,42 +843,41 @@ int bundle_free_exported_argv(int argc, char ***argv)
        return BUNDLE_ERROR_NONE;
 }
 
-       bundle *
-bundle_import_from_argv(int argc, char **argv)
+bundle *bundle_import_from_argv(int argc, char **argv)
 {
+       int idx;
+       int type;
+       keyval_t *kv;
+       keyval_array_t *kva;
+       unsigned char *byte;
+       char *encoded_byte;
+       unsigned int byte_size;
+       bundle *b;
+
        if (!argv) {
                set_last_result(BUNDLE_ERROR_INVALID_PARAMETER);
                return NULL;  /* TC_FIX error handling for argv =NULL*/
        }
 
-       bundle *b = bundle_create();
-       if (!b)
+       b = bundle_create();
+       if (!b) {
+               set_last_result(BUNDLE_ERROR_OUT_OF_MEMORY);
                return NULL;
+       }
 
-
-       /*
-          int i;
-          for(i=0; i<argc; i++) {
-          BUNDLE_LOG_PRINT("[bundle-dbg] argv[%d]='%s'\n", i, argv[i]);
-          }
-        */
+       if (argc < 2) {
+               set_last_result(BUNDLE_ERROR_NONE);
+               return b;
+       }
 
        if (!argv[1] || strcmp(argv[1], TAG_IMPORT_EXPORT_CHECK)) {
-               /*BUNDLE_LOG_PRINT("\nit is not encoded");*/
-               int idx;
                /*start idx from one as argv[1] is user given argument*/
                for (idx = 1; idx + 1 < argc; idx = idx + 2)
                        bundle_add(b, argv[idx], argv[idx + 1]);
 
                return b;
        }
-       /*BUNDLE_LOG_PRINT("\nit is encoded");*/
-       int idx, type;
-       keyval_t *kv = NULL;
-       keyval_array_t *kva = NULL;
-       unsigned char *byte = NULL;
-       char *encoded_byte;
-       unsigned int byte_size;
+
        /* start idx from 2 as argv[1] is encoded */
        for (idx = 2; idx + 1 < argc; idx = idx + 2) {
                kv = NULL;
@@ -912,6 +911,7 @@ bundle_import_from_argv(int argc, char **argv)
                free(byte);
                byte = NULL;
        }
+
        set_last_result(BUNDLE_ERROR_NONE);
        return b;
 }