From: shingil.kang Date: Wed, 9 Mar 2016 02:02:10 +0000 (+0900) Subject: Fixed sources reported by static code analysis tool. X-Git-Tag: submit/tizen/20160309.023941^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=845160f17df2ae504382893ab1374aa5b02968d7;p=sdk%2Ftarget%2Fsdbd.git Fixed sources reported by static code analysis tool. Change-Id: I5307232da32f736c3686ea0a080eea18a09db962 Signed-off-by: shingil.kang --- diff --git a/src/file_sync_service.c b/src/file_sync_service.c index cfe3e7f..61842a7 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -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 diff --git a/src/properties.c b/src/properties.c index 42e5785..dc76a69 100644 --- a/src/properties.c +++ b/src/properties.c @@ -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; } diff --git a/src/sdb.c b/src/sdb.c index 52e520f..175c3ff 100644 --- 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); diff --git a/src/transport_local.c b/src/transport_local.c index 8e8029b..1daa143 100644 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -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) { diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index 0237e5a..ef28284 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -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);