From e28ef796613384efd8b1096c93fdb634a48ecbf6 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Thu, 27 Nov 2014 15:25:18 +0900 Subject: [PATCH] emulator: detecting some error cases Detecting some error cases in profile conf file. Quotes can be used in default value section from now. Change-Id: Ib58676dcf1527b0e1d808aa079f25283b716b007 Signed-off-by: SeokYeon Hwang --- tizen/src/emulator_options.c | 43 +++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/tizen/src/emulator_options.c b/tizen/src/emulator_options.c index 28f09e74be..7a5df2b48a 100644 --- a/tizen/src/emulator_options.c +++ b/tizen/src/emulator_options.c @@ -33,7 +33,7 @@ #include "emul_state.h" #define LINE_LIMIT 1024 -#define TOKEN_LIMIT 128 +#define TOKEN_LIMIT 1024 #define OPTION_LIMIT 256 struct variable { @@ -93,6 +93,7 @@ void set_variable(const char * const arg1, const char * const arg2, var->name = name; var->value = value; + QTAILQ_INSERT_TAIL(&variables, var, entry); } @@ -137,7 +138,16 @@ static char *substitute_variables(char *src) int i = 0; int start_index = -1; int end_index = -1; - char *str = g_strdup(src); + char *str; + + // strip "" + int len = strlen(src); + if (src[0] == '"' && src[len - 1] == '"') { + src[len - 1] = '\0'; + str = g_strdup(src + 1); + } else { + str = g_strdup(src); + } for (i = 0; str[i]; ++i) { if(str[i] == '$' && str[i + 1] && str[i + 1] == '{') { @@ -199,7 +209,7 @@ static char *substitute_variables(char *src) bool load_profile_default(const char * const conf, const char * const profile) { - int classification = 0; + int classification = -1; char str[LINE_LIMIT]; char *filename; FILE *file = NULL; @@ -233,21 +243,24 @@ bool load_profile_default(const char * const conf, const char * const profile) do { if (!str[i] || - (!in_quote && - (str[i] == ' ' || str[i] == '\t' || str[i] == '#' - || str[i] == '\r' || str[i] == '\n')) || - (in_quote && str[i] == '"')) { + (!in_quote && + (str[i] == ' ' || str[i] == '\t' || str[i] == '#' + || str[i] == '\r' || str[i] == '\n'))) { if (start_index != -1) { - g_strlcpy(token, str + start_index, - i - start_index + 1); + int len = i - start_index + 1; + if (len < TOKEN_LIMIT) { + g_strlcpy(token, str + start_index, len); + } + else { + // TODO: error handling... + } } } + else if (str[i] == '"') { + in_quote = in_quote ? false : true; + } else { if (start_index < 0) { - if (str[i] == '"') { - in_quote = true; - ++i; - } start_index = i; } } @@ -275,6 +288,10 @@ bool load_profile_default(const char * const conf, const char * const profile) // process line switch (classification) { + case -1: // error + fprintf(stderr, "conf file error !!!\n"); + // TODO: assert ?? + break; case 0: // default variables { gchar **splitted = g_strsplit(token, "=", 2); -- 2.34.1