From: SeokYeon Hwang Date: Tue, 29 Dec 2015 04:52:03 +0000 (+0900) Subject: emulator_options: fix critical bug X-Git-Tag: Tizen_Studio_1.3_Release_p2.3~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ae4b10e56ad35166a834fa95f059d1f1c0facc0;p=sdk%2Femulator%2Fqemu.git emulator_options: fix critical bug 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 (cherry picked from commit 4953ab7043e544828af2f8c4f0dd162158d8c661) Signed-off-by: Sooyoung Ha --- diff --git a/tizen/src/emul_state.c b/tizen/src/emul_state.c index 6565740576..96b6433fc4 100644 --- a/tizen/src/emul_state.c +++ b/tizen/src/emul_state.c @@ -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; diff --git a/tizen/src/emulator.c b/tizen/src/emulator.c index 86e26b4777..a39f0de502 100644 --- a/tizen/src/emulator.c +++ b/tizen/src/emulator.c @@ -394,7 +394,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; diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index 0cda59b4c3..30f9ebc83d 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -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; } diff --git a/tizen/src/emulator_options.h b/tizen/src/emulator_options.h index 58f7867af7..efc995a71e 100644 --- a/tizen/src/emulator_options.h +++ b/tizen/src/emulator_options.h @@ -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,