Fix crash if argument number is wrong in bundle_import_from_argv 42/34342/1
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 8 Jan 2015 11:38:09 +0000 (12:38 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 23 Jan 2015 14:41:36 +0000 (15:41 +0100)
By introducing this, if argument number will be wrong, the not matching
argument will be skipped.
I would prefer not to return error as I'm not sure
if platform will use it correctly.

Change-Id: I71544a50e7959e7a77718e221382ac400437eb95

src/bundle.c

index 2d9902c..69b37dd 100755 (executable)
@@ -757,7 +757,7 @@ bundle_import_from_argv(int argc, char **argv)
        {
                /*BUNDLE_LOG_PRINT("\nit is not encoded");*/
                int idx;
-               for (idx = 1; idx < argc; idx = idx + 2) {        /*start idx from one as argv[1] is user given argument*/
+               for (idx = 1; idx + 1 < argc; idx = idx + 2) {        /*start idx from one as argv[1] is user given argument*/
                        bundle_add(b, argv[idx], argv[idx + 1]);
                }
                return b;
@@ -769,7 +769,7 @@ bundle_import_from_argv(int argc, char **argv)
        unsigned char *byte = NULL;
        char *encoded_byte;
        unsigned int byte_size;
-       for(idx = 2; idx < argc; idx = idx+2) {  // start idx from 2 as argv[1] is encoded
+       for(idx = 2; idx + 1 < argc; idx = idx+2) {  // start idx from 2 as argv[1] is encoded
                kv = NULL;
                kva = NULL;