emulator: detecting some error cases 09/30909/1
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 27 Nov 2014 06:25:18 +0000 (15:25 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 27 Nov 2014 06:25:18 +0000 (15:25 +0900)
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 <syeon.hwang@samsung.com>
tizen/src/emulator_options.c

index 28f09e74be1d16cec593754a809929faae8bbdc0..7a5df2b48a5ceb6b16d529a1604f097ad886e2da 100644 (file)
@@ -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);