emuld: refactoring code 90/56890/6
authorChulHo Song <ch81.song@samsung.com>
Wed, 13 Jan 2016 10:28:21 +0000 (19:28 +0900)
committerChulHo Song <ch81.song@samsung.com>
Wed, 2 Mar 2016 04:54:24 +0000 (13:54 +0900)
    strtok  ->  strtok_r
    strcpy  ->  strncpy
    strcat  ->  strncat
    sprintf ->  snprintf

Change-Id: Id59654828f6ca228af645cbd049c25e9622dfd09
Signed-off-by: ChulHo Song <ch81.song@samsung.com>
src/common.cpp
src/emuld.cpp
src/libemuld/msgproc.cpp
src/mobile.cpp
src/msgproc_hds.cpp
src/msgproc_location.cpp
src/msgproc_package.cpp
src/msgproc_vconf.cpp
src/net.cpp
src/tv.cpp

index b5a8d1048edf2c79d5fa7e21573d1bb4de41dc6a..9a655ad43b17acdf140cdaeeb6e213a1dbd6d81a 100644 (file)
@@ -47,6 +47,7 @@
 #define DEFAULT_PAYLOAD_SIZE 8192
 #define MAX_PAYLOAD_SIZE 65536
 #define MKDIR_MODE (S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
+#define MAX_DIGITS_INT 10            // in decimal
 
 unsigned int msize = MAX_PAYLOAD_SIZE;
 
@@ -142,7 +143,6 @@ int try_mount(char* tag, char* path)
 
     snprintf(mount_opt, sizeof(mount_opt), "trans=virtio,version=9p2000.L,msize=%u", msize - P9_FCALL_SIZE);
 
-
     ret = mount(tag, path, "9p", 0, mount_opt);
 
     if (ret == -1)
@@ -247,13 +247,12 @@ static void low_memory_cb(keynode_t* pKey, void* pData)
         {
             int value = vconf_keynode_get_int(pKey);
             LOGDEBUG("key = %s, value = %d(int)", vconf_keynode_get_name(pKey), value);
-            char *buf = (char*)malloc(sizeof(int));
+            char *buf = (char*)malloc(MAX_DIGITS_INT + 1);
             if (!buf) {
                 LOGERR("insufficient memory available");
                 return;
             }
-
-            sprintf(buf, "%d", vconf_keynode_get_int(pKey));
+            snprintf(buf, MAX_DIGITS_INT + 1, "%d", vconf_keynode_get_int(pKey));
             send_to_ecs(IJTYPE_VCONF, GROUP_MEMORY, STATUS, buf);
 
             free(buf);
index 091ac1535697d8dff6ee6a90118992c2689927e2..6f2d0663e40cc7e44e802a084758ee021326deab 100644 (file)
@@ -77,7 +77,7 @@ static void init_plugins(void)
 
     while ((dir_ent = readdir(dirp)))
     {
-        sprintf(plugin_path, "%s/%s", EMULD_PLUGIN_DIR, dir_ent->d_name);
+        snprintf(plugin_path, sizeof(plugin_path), "%s/%s", EMULD_PLUGIN_DIR, dir_ent->d_name);
 
         LOGDEBUG("Try to load plugin (%s)", plugin_path);
 
@@ -223,7 +223,7 @@ static void recv_from_evdi(evdi_fd fd)
         {
             if (errno != EAGAIN)
             {
-                LOGERR("EAGAIN");
+                LOGERR("read failed. errno = %d", errno);
                 return;
             }
         }
@@ -242,12 +242,12 @@ static void recv_from_evdi(evdi_fd fd)
     ijcommand ijcmd;
     readed = g_synbuf.read(ijcmd.cmd, ID_SIZE);
 
-    LOGDEBUG("ij id : %s", ijcmd.cmd);
-
     // TODO : check
     if (readed < ID_SIZE)
         return;
 
+    LOGDEBUG("ij id : %s", ijcmd.cmd);
+
     // read header
     readed = g_synbuf.read((char*)&ijcmd.msg, HEADER_SIZE);
     if (readed < HEADER_SIZE)
@@ -408,9 +408,9 @@ static void* handling_network(void* data)
     send_default_mount_req();
 
     ret = valid_hds_path((char*)HDS_DEFAULT_PATH);
-    LOGINFO("check directory '/mnt/host' for default fileshare: %d", ret);
+    LOGINFO("check directory '%s' for default fileshare: %d", HDS_DEFAULT_PATH, ret);
     ret = try_mount((char*)HDS_DEFAULT_TAG, (char*)HDS_DEFAULT_PATH);
-    LOGINFO("try mount /mnt/host for default fileshare: %d", ret);
+    LOGINFO("try mount %s for default fileshare: %d", HDS_DEFAULT_PATH, ret);
     if (ret == 0) {
         send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, HDS_ACTION_DEFAULT, (char*)HDS_DEFAULT_TAG);
     }
@@ -510,7 +510,7 @@ int main( int argc , char *argv[])
 
     ret = pthread_join(tid[TID_NETWORK], &retval);
     if (ret < 0) {
-        LOGERR("validate package pthread join is failed.");
+        LOGERR("message loop pthread join is failed.");
     }
 
     ret = pthread_join(conn_thread_t, &retval);
index d62cdef87859d94551643fc7e9fb5e1a792bed4f..f268dfdd07b8b9580db71e9f68e6d5afbe26b542 100644 (file)
@@ -61,8 +61,9 @@ bool msgproc_add(const char* name, const char* cmd, msgproc func, msgproc_prio p
         LOGWARN("Failed to allocate memory");
         return false;
     }
-    strcpy(pMsgProc->name, name);
-    strcpy(pMsgProc->cmd, cmd);
+    memset(pMsgProc, 0, sizeof(emuld_msgproc));
+    strncpy(pMsgProc->name, name, NAME_LEN - 1);
+    strncpy(pMsgProc->cmd, cmd, CMD_SIZE - 1);
     pMsgProc->func = func;
     pMsgProc->next = NULL;
     pPrev->next = pMsgProc;
index d68f132772564569433f544ae10dd9e99ce33cb2..63d60bd6485d8f0a5da5d06ed826b4715db6aa39 100644 (file)
@@ -145,57 +145,57 @@ int parse_motion_data(int len, char *buffer)
     switch(x)
     {
     case 1: // double tap
-        sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_DETECTION);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_DETECTION);
         systemcall(command);
     //  memset(command, '\0', sizeof(command));
     //  sprintf(command, "vconftool set -t int memory/private/sensor/800004 %d -i -f", SENSOR_MOTION_DOUBLETAP_NONE);
     //  systemcall(command);
         break;
     case 2: // shake start
-        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_DETECTED);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_DETECTED);
         systemcall(command);
         memset(command, '\0', sizeof(command));
-        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_CONTINUING);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_CONTINUING);
         systemcall(command);
         break;
     case 3: // shake stop
-        sprintf(command, "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_FINISHED);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800002 %d -i -f", SENSOR_MOTION_SHAKE_FINISHED);
         systemcall(command);
         break;
     case 4: // snap x+
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
         systemcall(command);
         break;
     case 5: // snap x-
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
         systemcall(command);
         break;
     case 6: // snap y+
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Y);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Y);
         systemcall(command);
         break;
     case 7: // snap y-
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Y);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Y);
         systemcall(command);
         break;
     case 8: // snap z+
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Z);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_Z);
         systemcall(command);
         break;
     case 9: // snap z-
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Z);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_Z);
         systemcall(command);
         break;
     case 10: // snap left
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_NEGATIVE_X);
         systemcall(command);
         break;
     case 11: // snap right
-        sprintf(command, "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800001 %d -i -f", SENSOR_MOTION_SNAP_POSITIVE_X);
         systemcall(command);
         break;
     case 12: // move to call (direct call)
-        sprintf(command, "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
+        snprintf(command, sizeof(command), "vconftool set -t int memory/private/sensor/800020 %d -i -f", SENSOR_MOTION_MOVE_MOVETOCALL);
         systemcall(command);
         break;
     default:
@@ -359,7 +359,7 @@ int parse_rssi_data(int len, char *buffer)
 
     x = atoi(tmpbuf);
 
-    sprintf(command, "vconftool set -t int memory/telephony/rssi %d -i -f", x);
+    snprintf(command, sizeof(command), "vconftool set -t int memory/telephony/rssi %d -i -f", x);
     systemcall(command);
 
     return 0;
index 391ea8d87ad1689be5691056ce36d0d4b37fd8c5..8b62469eb354038b196cff69bdd9f28a8f0f13e5 100644 (file)
@@ -40,15 +40,16 @@ static const char* hds_available_path [] = {
 static bool get_tag_path(char* data, char** tag, char** path)
 {
     char token[] = "\n";
+    char *saveptr;
 
     LOGINFO("get_tag_path data : %s", data);
-    *tag = strtok(data, token);
+    *tag = strtok_r(data, token, &saveptr);
     if (*tag == NULL) {
         LOGERR("data does not have a correct tag: %s", data);
         return false;
     }
 
-    *path = strtok(NULL, token);
+    *path = strtok_r(NULL, token, &saveptr);
     if (*path == NULL) {
         LOGERR("data does not have a correct path: %s", data);
         return false;
@@ -181,27 +182,31 @@ bool msgproc_hds(ijcommand* ijcmd)
 
     LOGINFO("action: %d, data: %s", ijcmd->msg.action, data);
     if (ijcmd->msg.action == 1) {
-        if (pthread_create(&tid[TID_HDS_ATTACH], NULL, mount_hds, (void*)data) != 0) {
-            if (!get_tag_path(data, &tag, &path)) {
-                LOGERR("mount pthread_create fail - wrong tag or path.");
-                return true;
-            }
-            LOGERR("mount hds pthread create fail!");
-            send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 2, tag);
+        if (pthread_create(&tid[TID_HDS_ATTACH], NULL, mount_hds, (void*)data) == 0) {
+            return true;
+        }
+        LOGERR("mount hds pthread create fail!");
+        if (!get_tag_path(data, &tag, &path)) {
+            LOGERR("mount pthread_create fail - wrong tag or path.");
+            free(data);
+            return true;
         }
+        send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 2, tag);
     } else if (ijcmd->msg.action == 2) {
-        if (pthread_create(&tid[TID_HDS_DETACH], NULL, umount_hds, (void*)data) != 0) {
-            if (!get_tag_path(data, &tag, &path)) {
-                LOGERR("umount pthread_create fail - wrong tag or path.");
-                free(data);
-                return true;
-            }
-            LOGERR("umount hds pthread create fail!");
-            send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 4, tag);
+        if (pthread_create(&tid[TID_HDS_DETACH], NULL, umount_hds, (void*)data) == 0) {
+            return true;
         }
+        LOGERR("umount hds pthread create fail!");
+        if (!get_tag_path(data, &tag, &path)) {
+            LOGERR("umount pthread_create fail - wrong tag or path.");
+            free(data);
+            return true;
+        }
+        send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 4, tag);
     } else {
         LOGERR("unknown action cmd.");
     }
+
     free(data);
     return true;
 }
index 6ffc92f4f14caa6f4b05d08fefbb52a11e812edb..d1e8afd2cd78495d74da64e1a45e5380cc100180 100644 (file)
@@ -51,7 +51,7 @@ static char* get_location_status(void* p)
         message = (char*)malloc(5);
         memset(message, 0, 5);
 
-        ret = sprintf(message, "%d", mode);
+        ret = snprintf(message, 5, "%d", mode);
         if (ret < 0) {
             free(message);
             message = 0;
@@ -69,7 +69,7 @@ static char* get_location_status(void* p)
 
         message = (char*)malloc(256);
         memset(message, 0, 256);
-        ret = sprintf(message, "%d,%s", mode, temp);
+        ret = snprintf(message, 256, "%d,%s", mode, temp);
         if (ret < 0) {
             free(message);
             message = 0;
@@ -99,7 +99,7 @@ static char* get_location_status(void* p)
 
         message = (char*)malloc(128);
         memset(message, 0, 128);
-        ret = sprintf(message, "%d,%f,%f,%f,%f", mode, latitude, logitude, altitude, accuracy);
+        ret = snprintf(message, 128, "%d,%f,%f,%f,%f", mode, latitude, logitude, altitude, accuracy);
         if (ret < 0) {
             free(message);
             message = 0;
@@ -137,7 +137,7 @@ static void* getting_location(void* data)
         return NULL;
     }
 
-    switch(param->ActionID)
+    switch (param->ActionID)
     {
         case LOCATION_STATUS:
             msg = get_location_status((void*)packet);
@@ -176,7 +176,7 @@ static void* getting_location(void* data)
         free(tmp);
     }
 
-    if(msg != 0)
+    if (msg != 0)
     {
         free(msg);
         msg = 0;
@@ -192,8 +192,9 @@ static void* getting_location(void* data)
 
 void setting_location(char* databuf)
 {
-    chars = strchr(databuf, ',');
+    char *s = strchr(databuf, ',');
     int err = 0;
+    char *saveptr;
     if (s == NULL) { // SET MODE
         int mode = atoi(databuf);
 
@@ -208,13 +209,13 @@ void setting_location(char* databuf)
     } else {
         *s = '\0';
         int mode = atoi(databuf);
-        if(mode == 1) { // NMEA MODE (LOG MODE)
+        if (mode == 1) { // NMEA MODE (LOG MODE)
             err = vconf_set_str(VCONF_FILENAME, s+1);
             LOGFAIL(err, "Set FileName failed. name = %s", s+1);
             err = vconf_set_int(VCONF_REPLAYMODE, mode);
             LOGFAIL(err, "Set ReplayMode failed. mode = %d", mode);
         } else if (mode == 2) {
-            char* ptr = strtok(s+1, ",");
+            char* ptr = strtok_r(s+1, ",", &saveptr);
             double value = 0.0;
 
             // Latitude
@@ -223,19 +224,19 @@ void setting_location(char* databuf)
             LOGFAIL(err, "Set ManualLatitude failed. value = %f", value);
 
             // Longitude
-            ptr = strtok(NULL, ",");
+            ptr = strtok_r(NULL, ",", &saveptr);
             value = atof(ptr);
             err = vconf_set_dbl(VCONF_MLONGITUDE, value);
             LOGFAIL(err, "Set ManualLongitude failed. value = %f", value);
 
             // Altitude
-            ptr = strtok(NULL, ",");
+            ptr = strtok_r(NULL, ",", &saveptr);
             value = atof(ptr);
             err = vconf_set_dbl(VCONF_MALTITUDE, value);
             LOGFAIL(err, "Set ManualAltitude failed. value = %f", value);
 
             // Accuracy
-            ptr = strtok(NULL, ",");
+            ptr = strtok_r(NULL, ",", &saveptr);
             value = atof(ptr);
             err = vconf_set_dbl(VCONF_MHACCURACY, value);
             LOGFAIL(err, "Set ManualHAccuracy failed. value = %f", value);
index 0d260d9c1aee156f182abecee79bf3f9efe52f38..f06f10397bf1323a3fa193347b9059bd5ce59da2 100644 (file)
@@ -55,7 +55,7 @@ static bool do_rpm_execute(char* pkgs)
 
     memset(buf, 0, sizeof(buf));
     while(fgets(buf, sizeof(buf), fp)) {
-        LOGINFO("[rpm]%s", buf);
+        LOGINFO("[rpm] %s", buf);
         memset(buf, 0, sizeof(buf));
     }
 
@@ -82,6 +82,7 @@ static void remove_package(char* data)
     char *addon = NULL;
     char *copy = strdup(data);
     size_t remain;
+    char *saveptr;
     if (copy == NULL) {
         LOGERR("Failed to copy data.");
         return;
@@ -89,10 +90,10 @@ static void remove_package(char* data)
 
     memset(pkg_list, 0, sizeof(pkg_list));
 
-    strcpy(pkg_list, "rm -rf ");
+    strncpy(pkg_list, "rm -rf ", sizeof("rm -rf "));
 
-    strcat(pkg_list, PATH_PACKAGE_INSTALL);
-    addon = strtok(copy, token);
+    strncat(pkg_list, PATH_PACKAGE_INSTALL, sizeof(PATH_PACKAGE_INSTALL));
+    addon = strtok_r(copy, token, &saveptr);
 
     if (addon == NULL) {
         LOGERR("Addon is null");
@@ -146,6 +147,7 @@ static bool do_package(int action, char* data)
     char *addon = NULL;
     char pkg_list[MAX_PKGS_BUF];
     size_t remain;
+    char *saveptr;
 
     if (data == NULL) {
         LOGERR("Add on package list is empty");
@@ -154,36 +156,36 @@ static bool do_package(int action, char* data)
 
     memset(pkg_list, 0, sizeof(pkg_list));
 
-    strcpy(pkg_list, "rpm");
+    strncpy(pkg_list, "rpm", sizeof("rpm"));
 
     if (action == 1) {
-        strcat(pkg_list, " ");
-        strcat(pkg_list, RPM_CMD_QUERY);
+        strncat(pkg_list, " ", sizeof(" "));
+        strncat(pkg_list, RPM_CMD_QUERY, sizeof(RPM_CMD_QUERY));
     } else if (action == 2) {
-        strcat(pkg_list, " ");
-        strcat(pkg_list, RPM_CMD_INSTALL);
+        strncat(pkg_list, " ", sizeof(" "));
+        strncat(pkg_list, RPM_CMD_INSTALL, sizeof(RPM_CMD_INSTALL));
     } else {
         LOGERR("Unknown action.");
         return false;
     }
-    addon = strtok(data, token); // for addon path
+    addon = strtok_r(data, token, &saveptr); // for addon path
 
     if (addon == NULL) {
         LOGERR("Addon is null");
         return false;
     }
 
-    pkg = strtok(NULL, token);
+    pkg = strtok_r(NULL, token, &saveptr);
     while (pkg != NULL) {
         if (action == 1) {
             pkg[strlen(pkg) - 4] = 0; //remove .rpm
         }
-        strcat(pkg_list, " ");
+        strncat(pkg_list, " ", sizeof(" "));
         if (action == 2) {
-            strcat(pkg_list, PATH_PACKAGE_INSTALL);
+            strncat(pkg_list, PATH_PACKAGE_INSTALL, sizeof(PATH_PACKAGE_INSTALL));
             remain = MAX_PKGS_BUF - strnlen(pkg_list, MAX_PKGS_BUF) - strlen("/");
             strncat(pkg_list, addon, remain - 1); // terminating null byte
-            strcat(pkg_list, "/");
+            strncat(pkg_list, "/", sizeof("/"));
         }
 
         remain = MAX_PKGS_BUF - strnlen(pkg_list, MAX_PKGS_BUF) - strlen(" 2>&1");
@@ -195,11 +197,10 @@ static bool do_package(int action, char* data)
 
         strncat(pkg_list, pkg, remain - 1); // terminating null byte
 
-        pkg = strtok(NULL, token);
+        pkg = strtok_r(NULL, token, &saveptr);
     }
 
-    strcat(pkg_list, " ");
-    strcat(pkg_list, "2>&1");
+    strncat(pkg_list, " 2>&1", sizeof(" 2>&1"));
 
     LOGINFO("[cmd] %s", pkg_list);
     if (action == 1 && do_rpm_execute(pkg_list)) {
index 40c596aac367f779baa0c57423d88994044e2ed1..2b55e06fcc11e0c6959c73c7cd738a3461ad6730 100644 (file)
@@ -41,8 +41,14 @@ static void* get_vconf_value(void* data)
     char *value = NULL;
     vconf_res_type *vrt = (vconf_res_type*)data;
 
+    if (!vrt)
+    {
+        LOGERR("vconf data is null");
+        pthread_exit((void *) 0);
+    }
+
     if (!check_possible_vconf_key(vrt->vconf_key)) {
-        LOGERR("%s is not available key.");
+        LOGERR("%s is not available key.", vrt->vconf_key);
     } else {
         int length = get_vconf_status(&value, vrt->vconf_type, vrt->vconf_key);
         if (length == 0 || !value) {
@@ -65,11 +71,17 @@ static void* set_vconf_value(void* data)
 {
     pthread_detach(pthread_self());
 
-    vconf_res_type *vrt = (vconf_res_type*)data;
     int val = -1;
+    vconf_res_type *vrt = (vconf_res_type*)data;
+
+    if (!vrt)
+    {
+        LOGERR("vconf data is null");
+        pthread_exit((void *) 0);
+    }
 
     if (!check_possible_vconf_key(vrt->vconf_key)) {
-        LOGERR("%s is not available key.");
+        LOGERR("%s is not available key.", vrt->vconf_key);
     } else {
         keylist_t *get_keylist;
         keynode_t *pkey_node = NULL;
@@ -151,10 +163,14 @@ bool msgproc_vconf(ijcommand* ijcmd)
     const int tmpsize = ijcmd->msg.length;
     char token[] = "\n";
     char tmpdata[tmpsize];
+    char *saveptr;
+    int vconf_key_size;
+    int vconf_val_size;
+
     memcpy(tmpdata, ijcmd->data, tmpsize);
 
     char* ret = NULL;
-    ret = strtok(tmpdata, token);
+    ret = strtok_r(tmpdata, token, &saveptr);
     if (!ret) {
         LOGERR("vconf type is empty");
         return true;
@@ -181,32 +197,33 @@ bool msgproc_vconf(ijcommand* ijcmd)
         goto error;
     }
 
-    ret = strtok(NULL, token);
+    ret = strtok_r(NULL, token, &saveptr);
     if (!ret) {
         LOGERR("vconf key is empty");
         goto error;
     }
-
-    vrt->vconf_key = (char*)malloc(strlen(ret) + 1);
+    vconf_key_size = strlen(ret);
+    vrt->vconf_key = (char*)malloc(vconf_key_size + 1);
     if (!vrt->vconf_key) {
         LOGERR("insufficient memory available");
         goto error;
     }
-    sprintf(vrt->vconf_key, "%s", ret);
+    snprintf(vrt->vconf_key, vconf_key_size + 1, "%s", ret);
 
     if (ijcmd->msg.action == VCONF_SET) {
-        ret = strtok(NULL, token);
+        ret = strtok_r(NULL, token, &saveptr);
         if (!ret) {
             LOGERR("vconf value is empty");
             goto error2;
         }
 
-        vrt->vconf_val = (char*)malloc(strlen(ret) + 1);
+        vconf_val_size = strlen(ret);
+        vrt->vconf_val = (char*)malloc(vconf_val_size + 1);
         if (!vrt->vconf_val) {
             LOGERR("insufficient memory available");
             goto error2;
         }
-        sprintf(vrt->vconf_val, "%s", ret);
+        snprintf(vrt->vconf_val, vconf_val_size + 1, "%s", ret);
 
         if (pthread_create(&tid[TID_VCONF], NULL, set_vconf_value, (void*)vrt) == 0) {
             return true;
index efe0a1d971b772ba717aff2569f8027febe76391..1c07e3ceb935d78dcce5176cf537a95a6f04f544 100644 (file)
@@ -430,7 +430,7 @@ void set_guest_addr()
             LOGERR("Socket open error");
             return;
         }
-        strcpy(ifrq.ifr_name, "eth0");
+        strncpy(ifrq.ifr_name, "eth0", sizeof("eth0"));
         while (ioctl(fd, SIOCGIFADDR, &ifrq) < 0) {
             /* while to get ip address */
             usleep(100);
index 7a4fb1abeb4045057ded5a8d8159a78fe137c96b..d12876354f2f3956e36ab6ac588b72b25afe4871 100644 (file)
@@ -166,7 +166,7 @@ int get_voice_cmd()
 int send_guide_me()
 {
 
-    sprintf(s1, "%s", "guide me");
+    snprintf(s1, 10, "%s", "guide me");
 
     si_voice_result_data_s t_voice;
     t_voice.handle = 0;
@@ -183,7 +183,7 @@ int send_guide_me()
 int send_describe()
 {
 
-    sprintf(s1, "%s", "describe");
+    snprintf(s1, 10, "%s", "describe");
 
     si_voice_result_data_s t_voice;
     t_voice.handle = 0;
@@ -200,7 +200,7 @@ int send_describe()
 int send_left()
 {
 
-    sprintf(s1, "%s", "left");
+    snprintf(s1, 10, "%s", "left");
 
     si_voice_result_data_s t_voice;
     t_voice.m_Domain = 20;
@@ -216,7 +216,7 @@ int send_left()
 int send_right()
 {
 
-    sprintf(s1, "%s", "right");
+    snprintf(s1, 10, "%s", "right");
 
     si_voice_result_data_s t_voice;
     t_voice.m_Domain = 20;
@@ -244,11 +244,12 @@ bool msgproc_gesture(ijcommand* ijcmd)
     int command, ret, data;
     const int tmpsize = ijcmd->msg.length;
 
-    chardata_p = NULL;
+    char *data_p = NULL;
     char token[] = "\n";
     char tmpdata[tmpsize+1];
-    chars_cnt = NULL;
+    char *s_cnt = NULL;
     int cnt = 0;
+    char *saveptr;
 
     if (!SI_INIT) {
         ret = InitServer();
@@ -264,10 +265,10 @@ bool msgproc_gesture(ijcommand* ijcmd)
     memset(tmpdata, 0, tmpsize+1);
     memcpy(tmpdata, ijcmd->data, tmpsize);
 
-    s_cnt = strtok(tmpdata, token);
+    s_cnt = strtok_r(tmpdata, token, &saveptr);
     cnt = atoi(s_cnt);
 
-    while(data_p = strtok(NULL, token)) {
+    while(data_p = strtok_r(NULL, token, &saveptr)) {
         data = atoi(data_p);
     }
     printf("msgproc_gesture action : %d\n", ijcmd->msg.action);
@@ -418,7 +419,7 @@ bool msgproc_extinput(ijcommand* ijcmd)
         }
         /* get hdmi plugged state */
         for (i = 0; i < HDMI_CNT; i++) {
-            sprintf(command, "memory/sysman/hdmi%d", i+1);
+            snprintf(command, sizeof(command), "memory/sysman/hdmi%d", i+1);
             if (vconf_get_int(command, &onoff_state)) {
                 onoff_state = 0;
             }
@@ -426,7 +427,7 @@ bool msgproc_extinput(ijcommand* ijcmd)
         }
         /* get av plugged state */
         for (i = 0; i < AV_CNT; i++) {
-            sprintf(command, "memory/sysman/av%d", i+1);
+            snprintf(command, sizeof(command), "memory/sysman/av%d", i+1);
             if (vconf_get_int(command, &onoff_state)) {
                 onoff_state = 0;
             }
@@ -434,7 +435,7 @@ bool msgproc_extinput(ijcommand* ijcmd)
         }
         /* get comp plugged state */
         for (i = 0; i < COMP_CNT; i++) {
-            sprintf(command, "memory/sysman/comp%d", i+1);
+            snprintf(command, sizeof(command), "memory/sysman/comp%d", i+1);
             if (vconf_get_int(command, &onoff_state)) {
                 onoff_state = 0;
             }
@@ -449,7 +450,7 @@ bool msgproc_extinput(ijcommand* ijcmd)
             packet->group = 15;
             packet->action = 211;
             memcpy(tmp, packet, HEADER_SIZE);
-            sprintf(command, "%d:%d:%d:%d:%d:%d:%d:%d:",
+            snprintf(command, sizeof(command), "%d:%d:%d:%d:%d:%d:%d:%d:",
                     extinput[0], extinput[1], extinput[2], extinput[3], extinput[4], extinput[5], extinput[6], extinput[7]);
             memcpy(tmp + HEADER_SIZE, command, packet->length);
             ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_EI, (const char *)tmp, tmplen);
@@ -469,12 +470,13 @@ bool msgproc_extinput(ijcommand* ijcmd)
         char *section = NULL;
         unsigned int number = 0;
         unsigned int state = 0;
+        char *saveptr;
         memset(plugged, '\0', sizeof(plugged));
         memcpy(plugged, ijcmd->data, ijcmd->msg.length);
 
-        section = strtok(plugged, token);
+        section = strtok_r(plugged, token, &saveptr);
         number = (unsigned int)atoi(section);
-        section = strtok(NULL, token);
+        section = strtok_r(NULL, token, &saveptr);
         state = (unsigned int)atoi(section);
 
         if (number > MAX_EXTINPUT_COUNT) {
@@ -487,19 +489,19 @@ bool msgproc_extinput(ijcommand* ijcmd)
         case EXTINPUT_HDMI2:
         case EXTINPUT_HDMI3:
         case EXTINPUT_HDMI4:
-            sprintf(command, "vconftool set -t int memory/sysman/hdmi%d %d -i -f", number, state);
+            snprintf(command, sizeof(command), "vconftool set -t int memory/sysman/hdmi%d %d -i -f", number, state);
             break;
         case EXTINPUT_AV1:
-            sprintf(command, "vconftool set -t int memory/sysman/av1 %d -i -f", state);
+            snprintf(command, sizeof(command), "vconftool set -t int memory/sysman/av1 %d -i -f", state);
             break;
         case EXTINPUT_AV2:
-            sprintf(command, "vconftool set -t int memory/sysman/av2 %d -i -f", state);
+            snprintf(command, sizeof(command), "vconftool set -t int memory/sysman/av2 %d -i -f", state);
             break;
         case EXTINPUT_COMP1:
-            sprintf(command, "vconftool set -t int memory/sysman/comp1 %d -i -f", state);
+            snprintf(command, sizeof(command), "vconftool set -t int memory/sysman/comp1 %d -i -f", state);
             break;
         case EXTINPUT_COMP2:
-            sprintf(command, "vconftool set -t int memory/sysman/comp2 %d -i -f", state);
+            snprintf(command, sizeof(command), "vconftool set -t int memory/sysman/comp2 %d -i -f", state);
             break;
         }
         extinput[number-1] = state;