Fixed sources reported by static code analysis tool. 64/61564/3
authorshingil.kang <shingil.kang@samsung.com>
Wed, 9 Mar 2016 02:02:10 +0000 (11:02 +0900)
committershingil.kang <shingil.kang@samsung.com>
Wed, 9 Mar 2016 02:33:56 +0000 (11:33 +0900)
Change-Id: I5307232da32f736c3686ea0a080eea18a09db962
Signed-off-by: shingil.kang <shingil.kang@samsung.com>
src/file_sync_service.c
src/properties.c
src/sdb.c
src/transport_local.c
src/usb_funcfs_client.c

index cfe3e7f7be6ce19022a0d4b686d147a99df76a5b..61842a7227b7d074d93582e19a83aaaa1f388dc8 100644 (file)
@@ -92,7 +92,7 @@ static void set_syncfile_smack_label(char *src) {
             rc = smack_getlabel(dirname, &label, SMACK_LABEL_ACCESS);
             if (rc == 0 && label != NULL) {
                 if (smack_setlabel(src, label, SMACK_LABEL_ACCESS) == -1) {
-                    D("unable to set sync file smack label %s due to %s\n", label, strerror(errno));
+                    D("unable to set sync file smack label %s due to (errno:%d)\n", label, errno);
                 }
 
                 /* Todo: The following code is from tizen 2.4
@@ -109,7 +109,7 @@ static void set_syncfile_smack_label(char *src) {
         free(label_transmuted);
     } else {
         if (smack_setlabel(src, SMACK_SYNC_FILE_LABEL, SMACK_LABEL_ACCESS) == -1) {
-            D("unable to set sync file smack label %s due to %s\n", SMACK_SYNC_FILE_LABEL, strerror(errno));
+            D("unable to set sync file smack label %s due to (errno:%d)\n", SMACK_SYNC_FILE_LABEL, errno);
         }
 
         /* Todo: The following code is from tizen 2.4
index 42e5785945457facee7a9a4abd3d8d3677d6bf9e..dc76a69cf922a24a7334bd218a386afdc8bff8d0 100644 (file)
@@ -60,6 +60,7 @@ static void property_init(void)
     int i = 0;
     char buffer[PROPERTY_KEY_MAX+PROPERTY_VALUE_MAX+1];
     char *tok = NULL;
+    char *ptr;
 
     fd = unix_open(TIZEN_PROPERTY_FILE, O_RDONLY);
     if (fd < 0)
@@ -67,12 +68,14 @@ static void property_init(void)
     for(;;) {
         if(read_line(fd, buffer, PROPERTY_KEY_MAX+PROPERTY_VALUE_MAX+1) < 0)
             break;
-        tok = strtok(buffer, PROPERTY_SEPARATOR);
+        tok = strtok_r(buffer, PROPERTY_SEPARATOR, &ptr);
         for (i = 0; i < sdbd_config_element_cnt && sdbd_config[i].key ; i++) {
             if (!strcmp(tok, sdbd_config[i].key)) {
-                tok = strtok(NULL, PROPERTY_SEPARATOR);
-                strncpy(sdbd_config[i].value, tok, PROPERTY_VALUE_MAX);
-                D("property init key=%s, value=%s\n", sdbd_config[i].key, tok);
+                tok = strtok_r(NULL, PROPERTY_SEPARATOR, &ptr);
+                if(tok) {
+                    snprintf(sdbd_config[i].value, PROPERTY_VALUE_MAX, "%s", tok);
+                    D("property init key=%s, value=%s\n", sdbd_config[i].key, tok);
+                }
             }
         }
 
@@ -113,7 +116,7 @@ int property_set(const char *key, const char *value)
 
     for (i = 0; i < sdbd_config_element_cnt && sdbd_config[i].key; i++) {
         if (!strcmp(key,sdbd_config[i].key)) {
-            strncpy(sdbd_config[i].value, value, PROPERTY_VALUE_MAX);
+            snprintf(sdbd_config[i].value, PROPERTY_VALUE_MAX, "%s", value);
             D("property set key=%s, value=%s\n", key, value);
             break;
         }
index 52e520fa807fa3eff4e1a6996580b3a7e8dcea8b..175c3fffb2632ccf0f62b5f5d210ffe31a197c88 100644 (file)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -1416,10 +1416,10 @@ int set_developer_privileges() {
         }
     }
     // TODO: use pam later
-    char * env = malloc(strlen("HOME=") + strlen(HOME_DEV_PATH) + 1);
+    int env_size = strlen("HOME=") + strlen(HOME_DEV_PATH) + 1;
+    char * env = malloc(env_size);
     if(env == 0) fatal("failed to allocate for env string");
-    strcpy(env, "HOME=");
-    strcat(env, HOME_DEV_PATH);
+    snprintf(env, env_size, "HOME=%s", HOME_DEV_PATH);
     putenv(env);
     free(env);
 
index 8e8029bef2863babc74f3d05b12d01afce6f0c3b..1daa143f2316db7fc8d514460201d8aa7445531b 100644 (file)
@@ -431,7 +431,8 @@ static const char _ok_resp[]    = "ok";
  */
 static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int protocol) {
     int sock = -1;
-    char port[32]; /* string decimal representation for getaddrinfo */
+    int PORT_SIZE = 32;
+    char port[PORT_SIZE]; /* string decimal representation for getaddrinfo */
     struct addrinfo hints = {0};
     struct addrinfo *addresses, *curr_addr;
     int getaddr_ret;
@@ -455,7 +456,7 @@ static int send_msg_to_host_from_guest(const char *hostname, int host_port, char
 
     hints.ai_family = AF_INET;
 
-    sprintf(port, "%d", host_port);
+    snprintf(port, PORT_SIZE, "%d", host_port);
     getaddr_ret = getaddrinfo(hostname, port, &hints, &addresses);
 
     if (getaddr_ret != 0) {
index 0237e5ae2e3e26e77895a037839c86f65e33c415..ef2828415450094784d111a1814cdf949ff76452 100644 (file)
@@ -532,8 +532,8 @@ int ffs_usb_write(usb_handle *h, const void *data, int len)
     D("about to write (fd=%d, len=%d)\n", h->bulk_in, len);
     n = bulk_write(h->bulk_in, data, len);
     if(n != len) {
-        D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
-            h->bulk_in, n, errno, strerror(errno));
+        D("ERROR: fd = %d, n = %d, errno = %d\n",
+            h->bulk_in, n, errno);
         return -1;
     }
     D("[ done fd=%d ]\n", h->bulk_in);
@@ -555,8 +555,8 @@ int ffs_usb_read(usb_handle *h, void *data, int len)
     D("%d: about to read (fd=%d, len=%d)\n", getpid(), h->bulk_out, len);
     n = bulk_read(h->bulk_out, data, len);
     if(n != len) {
-        D("ERROR: fd = %d, n = %d, errno = %d (%s)\n",
-            h->bulk_out, n, errno, strerror(errno));
+        D("ERROR: fd = %d, n = %d, errno = %d\n",
+            h->bulk_out, n, errno);
         return -1;
     }
     D("[ done fd=%d ]\n", h->bulk_out);