silence stringio truncation warning 70/221770/1 accepted/tizen/unified/20200110.123621 submit/tizen/20200107.094751
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 7 Jan 2020 09:29:19 +0000 (18:29 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Tue, 7 Jan 2020 09:40:06 +0000 (18:40 +0900)
give a bigger number as a size and add nul byte at the end of array
in case of causing truncation.

Change-Id: I8db4fb74774810b83c2f92bd21ed4d1a0943b063

src/tdm_helper.c
src/tdm_server.c
tools/tdm_test_client.c

index 08477f1..5fe5403 100644 (file)
@@ -295,7 +295,7 @@ tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
                strncat(p, file, len);
                p += len;
                *(p++) = '.';
-               strncat(p, ext, 3);
+               strncat(p, ext, 4);
                p += 3;
                *p = '\0';
        } else {
index 25ad51d..3c32a54 100644 (file)
@@ -148,12 +148,11 @@ _tdm_server_get_process_name(pid_t pid, char *name, unsigned int size)
 
        len = fread(pname, sizeof(char), TDM_NAME_LEN, h);
        if (len == 0) {
-               strncpy(pname, "NO NAME", 7);
-               len = 8;
+               strncpy(pname, "NO NAME", sizeof(pname));
+               pname[sizeof(pname) - 1] = '\0';
        }
-       pname[len - 1] = '\0';
 
-       strncpy(name, pname, size - 1);
+       strncpy(name, pname, size);
        name[size - 1] = '\0';
 
        fclose(h);
@@ -1403,7 +1402,9 @@ _tdm_server_cb_debug(struct wl_client *client, struct wl_resource *resource, con
                char buffer[TDM_DEBUG_REPLY_MSG_LEN];
                int copylen = TDM_MIN(size, sizeof(buffer) - 1);
 
-               strncpy(buffer, m, copylen);
+               strncpy(buffer, m, sizeof(buffer));
+               buffer[sizeof(buffer) - 1] = '\0';
+
                m += copylen;
                size -= copylen;
 
index ab12626..14feed9 100644 (file)
@@ -520,7 +520,7 @@ _tdm_client_dump_buffer(tbm_surface_h buffer, const char *file)
                strncat(p, file, len);
                p += len;
                *(p++) = '.';
-               strncat(p, ext, 3);
+               strncat(p, ext, 4);
                p += 3;
                *p = '\0';
        } else {