source: fix some risky codes 13/154313/1
authorSooyoung Ha <yoosah.ha@samsung.com>
Tue, 10 Oct 2017 04:50:30 +0000 (13:50 +0900)
committerSooyoung Ha <yoosah.ha@samsung.com>
Tue, 10 Oct 2017 04:50:30 +0000 (13:50 +0900)
Change-Id: I09660d031e04a3318849c49f2fe933f6388e0627
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
src/default_plugin_appcmd.c
src/sdb.c
src/services.c
src/subprocess.c
src/transport.c

index 8ffb4e3..bd4986c 100644 (file)
@@ -315,7 +315,7 @@ static void appcmd_receiver_default(int fd_in, int fd_out)
 
     for(;;) {
         memset(buf, 0, sizeof(buf));
-        r = sdb_read(fd_in, buf, sizeof(buf));
+        r = sdb_read(fd_in, buf, sizeof(buf)-1);
         if (r == 0) {
             break;
         } else if(r < 0) {
@@ -480,11 +480,11 @@ static int exec_appcmd_shell_process(appcmd_info* p_info) {
     args[2] = p_info->shell_cmd;
 
     ptm_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp);
-    D("create_subprocess() ptm_fd=%d pid=%d\n", ptm_fd, pid);
     if (ptm_fd < 0) {
         D("cannot create service thread\n");
         return -1;
     }
+    D("create_subprocess() ptm_fd=%d pid=%d\n", ptm_fd, pid);
 
     if (p_info->receiver_func != NULL) {
         p_info->receiver_func(ptm_fd, p_info->fd);
index f614bfb..efb8999 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -1176,25 +1176,24 @@ void start_device_log(void)
     char    path_file[PATH_MAX] = {0, };
     struct tm now;
     time_t t;
-//    char value[PROPERTY_VALUE_MAX];
-    char* p_trace = get_sdb_log_conf("SDB_TRACE");
-    char* p_path = get_sdb_log_conf("SDBD_LOG_PATH");
+
     // read the trace mask from persistent property persist.sdb.trace_mask
     // give up if the property is not set or cannot be parsed
-
+    char* p_trace = get_sdb_log_conf("SDB_TRACE");
     if ((p_trace == NULL ) && !is_enable_sdbd_log()) {
         return;
     } else {
         free(p_trace);
     }
-
+    char* p_path = get_sdb_log_conf("SDBD_LOG_PATH");
     if (p_path) {
         snprintf(path_folder, sizeof(path_folder), "%s", p_path);
         free(p_path);
-    } else if (g_capabilities.log_path[0] != '\0')
+    } else if (g_capabilities.log_path[0] != '\0') {
         snprintf(path_folder, sizeof(path_folder), "%s", g_capabilities.log_path);
-    else
+    } else {
         return;
+    }
 
     tzset();
     time(&t);
index 2976230..b8fd31a 100644 (file)
@@ -455,6 +455,7 @@ static ssize_t recv_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
     } control_un;
     ssize_t ret;
 
+    memset(&msg, 0, sizeof(msg));
     msg.msg_control = control_un.control;
     msg.msg_controllen = sizeof(control_un.control);
 
index 6eb3ca0..9241d85 100644 (file)
@@ -40,6 +40,7 @@ static ssize_t send_fd(int fd, void *ptr, size_t nbytes, int sendfd)
         char control[CMSG_SPACE(sizeof(int))];
     } control_un;
 
+    memset(&msg, 0, sizeof(msg));
     msg.msg_control = control_un.control;
     msg.msg_controllen = sizeof(control_un.control);
 
index d6ecd66..49895e7 100644 (file)
@@ -823,6 +823,7 @@ void broadcast_transport(apacket *p)
                     t->connection_state = CS_PWLOCK;
                 }
             }
+            put_apacket(ap);
         }
     }
     sdb_mutex_unlock(&transport_lock);