[Tizen 6.0] Enable build with -Wformat-truncation warning 84/222284/1 accepted/tizen/unified/20200114.130626 submit/tizen/20200114.003051
authorMikhail Kashkarov <m.kashkarov@partner.samsung.com>
Wed, 18 Dec 2019 10:55:29 +0000 (13:55 +0300)
committerDongkyun Son <dongkyun.s@samsung.com>
Mon, 13 Jan 2020 06:08:53 +0000 (15:08 +0900)
nput_events.c:171:19: error: '%s' directive output may be truncated
writing up to 255 bytes into a region of size 117 [-Werror=format-truncation=]
  171 |       "/dev/input/%s", d->d_name);
      |                   ^~
input_events.c:170:5: note: 'snprintf' output between 12 and 267 bytes
into a destination of size 128
  170 |     snprintf(dev[count].fileName, MAX_FILENAME,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171 |       "/dev/input/%s", d->d_name);

ui_viewer_data.c:303:3: error: 'strncpy' specified bound depends on the length
of the source argument [-Werror=stringop-overflow=]
  303 |   strncpy(to, str, len);
      |   ^~~~~~~~~~~~~~~~~~~~~
ui_viewer_data.c:302:16: note: length computed here
  302 |   size_t len = strlen(str) + 1;
      |                ^~~~~~~~~~~

Change-Id: Ib009b0d1fb99bfd70f9936546d388fd5b29e80f4
Signed-off-by: Mikhail Kashkarov <m.kashkarov@partner.samsung.com>
daemon/input_events.c
ui_viewer/ui_viewer_data.c

index 4885a14..25cae12 100644 (file)
@@ -167,8 +167,12 @@ static void _get_fds(input_dev *dev, int input_id)
                        // start with "event"
                        // event file
                        if (!check_input(d->d_name, input_id)) {
-                               snprintf(dev[count].fileName, MAX_FILENAME,
-                                        "/dev/input/%s", d->d_name);
+                               if (snprintf(dev[count].fileName, MAX_FILENAME,
+                                            "/dev/input/%s",
+                                            d->d_name) >= MAX_FILENAME) {
+                                       LOGE("too long filename, truncated!");
+                                       break;
+                               }
                                dev[count].fd = open(dev[count].fileName,
                                                     O_RDWR | O_NONBLOCK);
                                count++;
index a12ce13..4d773d1 100644 (file)
@@ -300,7 +300,7 @@ char *pack_string(char *to, const char *str)
                return to + 1;
        } else {
                size_t len = strlen(str) + 1;
-               strncpy(to, str, len);
+               memcpy(to, str, len);
                return to + len;
        }
 }