emulator_options: fix critical bug
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 29 Dec 2015 04:52:03 +0000 (13:52 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Fri, 8 Jan 2016 10:32:23 +0000 (19:32 +0900)
Variable value is contaminated during it is processed. We fix this
issue and prevent a recurrence of this issue by using "const" keyword.

Conflicts:

        tizen/src/emul_state.c

Change-Id: I7d50a82a10a6b43b203e78b5394bf3eb8e0231a2
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
(cherry picked from commit 4953ab7043e544828af2f8c4f0dd162158d8c661)
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
tizen/src/emul_state.c
tizen/src/emulator.c
tizen/src/emulator_options.c
tizen/src/emulator_options.h

index 0dee63d0cff1c840cd26160666f5981928a7fce6..a4eaa4de9e3663af4e504cbc536d29e1796fe6b2 100644 (file)
@@ -76,12 +76,12 @@ const char *get_log_path(void)
         return log_path;
     }
 #endif
-    char *log_path = get_variable("log_path");
+    const char *log_path = get_variable("log_path");
 
     // if "log_path" is not exist, make it first
     if (!log_path) {
-        char *vms_path = get_variable("vms_path");
-        char *vm_name = get_variable("vm_name");
+        const char *vms_path = get_variable("vms_path");
+        const char *vm_name = get_variable("vm_name");
         if (!vms_path || !vm_name) {
             log_path = NULL;
         }
@@ -355,7 +355,7 @@ int get_emul_num_lock_state(void)
 /* drive image file */
 const char* get_drive_image_file(void)
 {
-    char *drive_image_file = get_variable("drive_image_file");
+    const char *drive_image_file = get_variable("drive_image_file");
 
     if (drive_image_file) {
         return drive_image_file;
index fd32e4023a0e29d408a4b9b673e6db8ae3deb50a..48b5d58e15bbe0967de1c4672e72d4b4330051ef 100644 (file)
@@ -393,7 +393,7 @@ static int emulator_main(int argc, char *argv[], char **envp)
 
     // set emulator resolution
     {
-        char *resolution = get_variable("resolution");
+        const char *resolution = get_variable("resolution");
         if (!resolution) {
             fprintf(stderr, "[resolution] is required.\n");
             return -1;
index 0cda59b4c33c202c0f09f9d9f6c0e5e775827f55..30f9ebc83dc1a128ef0177dbea90b00d12944026 100644 (file)
@@ -98,7 +98,7 @@ void set_variable(const char * const arg1, const char * const arg2,
     QTAILQ_INSERT_TAIL(&variables, var, entry);
 }
 
-char *get_variable(const char * const name)
+const char *get_variable(const char * const name)
 {
     struct variable *var = NULL;
 
@@ -134,7 +134,7 @@ static void reset_default_opts(void)
     }
 }
 
-static char *substitute_variables(char *src, bool recursive)
+static char *substitute_variables(const char *src, bool recursive)
 {
     int i = 0;
     int start_index = -1;
@@ -144,10 +144,9 @@ static char *substitute_variables(char *src, bool recursive)
     // strip ""
     int len = strlen(src);
     if (src[0] == '"' && src[len - 1] == '"') {
-        src[len - 1] = '\0';
-        str = g_strdup(src + 1);
+        str = g_strndup(src + 1, len -2);
     } else {
-        str = g_strdup(src);
+        str = g_strndup(src, len);
     }
 
     for (i = 0; str[i]; ++i) {
@@ -165,7 +164,7 @@ static char *substitute_variables(char *src, bool recursive)
             }
 
             char name[TOKEN_LIMIT];
-            char *value = NULL;
+            const char *value = NULL;
             char *buf = NULL;
             int length;
 
@@ -321,6 +320,7 @@ bool load_conf(const char * const conf)
     }
 
     fclose(file);
+
     return true;
 }
 
index 58f7867af741a19e9aa074729938f9a6887bd64a..efc995a71e424a1f63ce6b10d2c6a8cb2ff38adf 100644 (file)
@@ -32,7 +32,7 @@
 #include "emulator_common.h"
 
 void set_variable(const char * const arg1, const char * const arg2, bool override);
-char *get_variable(const char * const name);
+const char *get_variable(const char * const name);
 void reset_variables(void);
 bool load_conf(const char * const conf);
 bool assemble_emulator_args(int *qemu_argc, char **qemu_argv,