emuld: fix some defects 86/56286/1 accepted/tizen/mobile/20160107.101504 accepted/tizen/tv/20160107.101525 accepted/tizen/wearable/20160107.101540 submit/tizen/20160107.013154
authorChulHo Song <ch81.song@samsung.com>
Wed, 6 Jan 2016 04:46:21 +0000 (13:46 +0900)
committerChulHo Song <ch81.song@samsung.com>
Wed, 6 Jan 2016 04:46:21 +0000 (13:46 +0900)
change strcat to strncat.
check getline lineptr.

Change-Id: Icb1b0147e6fe15932358e1b3e94d7239b8342740
Signed-off-by: ChulHo Song <ch81.song@samsung.com>
src/common.cpp
src/net.cpp

index 3cf9738da4657a4cce8f03abd0d342be96a3f08a..d19c68649c98fd07654a63c155530c7f80de6b2c 100644 (file)
@@ -331,7 +331,8 @@ static void remove_package(char* data)
         free(copy);
         return;
     }
-    strcat(pkg_list, addon);
+
+    strncat(pkg_list, addon, remain - 1); // terminating null byte
 
     LOGINFO("remove packages: %s", pkg_list);
 
@@ -393,7 +394,7 @@ static bool do_package(int action, char* data)
             return false;
         }
 
-        strcat(pkg_list, pkg);
+        strncat(pkg_list, pkg, remain - 1); // terminating null byte
 
         pkg = strtok(NULL, token);
     }
index fbc1a4cb2e7d4eba2af055aca6453ecaeba63ccd..6723a96ff8f8a8e292a984b05fc45441f6d0eb47 100644 (file)
@@ -369,21 +369,27 @@ static int get_network_info(char str[], int str_size)
     int ret = 0;
 
     if (fp == NULL) {
-        LOGERR("fail to read /proc/cmdline");
+        LOGERR("failed to open /proc/cmdline");
         return -1;
     }
+
     if (getline(&line, &len, fp) != -1) {
         LOGINFO("line: %s", line);
         LOGINFO("len: %d", len);
     }
 
+    if (!line)
+    {
+        LOGERR("failed to read /proc/cmdline");
+        return -1;
+    }
+
     if (get_str_cmdline(line, IP_SUFFIX, str, str_size) < 1) {
         LOGINFO("could not get the (%s) value from cmdline. static ip does not set.", IP_SUFFIX);
         ret = -1;
     }
 
-    if(line)
-        free(line);
+    free(line);
     fclose(fp);
 
     LOGINFO("succeeded to get guest_net: %s", str);