Remove 'format-truncation' warning for GCC-9 76/220876/2 accepted/tizen/unified/20200106.141608 submit/tizen/20200103.083647
authorYunmi Ha <yunmi.ha@samsung.com>
Tue, 24 Dec 2019 07:07:50 +0000 (16:07 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 26 Dec 2019 01:55:15 +0000 (10:55 +0900)
Change-Id: I1ec0fe9415d76e0d6ce3539a7120fb0069e7f2b5
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/block/block.c
src/block/utils.c
src/core/modules.c

index 0c06b66f292d586091d0b4496ab416abc3ff0f8d..879fdf630551100870f883e6ed57980bc1feb08a 100644 (file)
@@ -622,7 +622,11 @@ static bool check_primary_partition(const char *devnode)
        str[len - 1] = '\0';
 
        for (i = 1; i <= 9; ++i) {
-               snprintf(str2, sizeof(str2), "%s%d", str, i);
+               if ((ret = snprintf(str2, sizeof(str2), "%s%d", str, i)) > sizeof(str2) - 1) {
+                       _E("Filename is longer than buffer. Need %d size of buffer.", ret + 1);
+                       continue;
+               }
+
                if (access(str2, R_OK) != 0)
                        continue;
 
@@ -939,7 +943,11 @@ void mmc_make_default_path(const char *mount_path)
        char mmc_path[FILE_NAME_LEN_MAX + 1] = {0, };
 
        for (i = 0; i < DIR_NUM; ++i) {
-               snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i]);
+               if ((ret = snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i])) > sizeof(mmc_path) - 1) {
+                       _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+                       continue;
+               }
+
                if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
                        _D("Path(%s) did not exist.", mmc_path);
                        ret = mkdir(mmc_path, 0777);
index 1c283ba11e0a304262e225a8943510262b50feaf..35889142273fa08d9ed0171bdb81eb8d1d16026a 100644 (file)
@@ -75,7 +75,10 @@ int print_open_files(const char *mount_point)
                        continue;
 
                pid = atoi(dir->d_name);
-               snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
+               if ((ret = snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid)) > PATH_MAX - 1) {
+                       _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+                       continue;
+               }
 
                fd = open(buf, O_RDONLY);
                if (fd < 0)
@@ -87,7 +90,11 @@ int print_open_files(const char *mount_point)
                        continue;
                cmdline[ret] = '\0';
 
-               snprintf(buf, PATH_MAX, "/proc/%d/fd", pid);
+               if ((ret = snprintf(buf, PATH_MAX, "/proc/%d/fd", pid)) > PATH_MAX - 1) {
+                       _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+                       continue;
+               }
+
                dp_child = opendir(buf);
                if (!dp_child)
                        continue;
@@ -98,7 +105,10 @@ int print_open_files(const char *mount_point)
                        if (ret != 0)
                                break;
 
-                       snprintf(check_path, PATH_MAX, "%s/%s", buf, dir_child->d_name);
+                       if ((ret = snprintf(check_path, PATH_MAX, "%s/%s", buf, dir_child->d_name)) > PATH_MAX - 1) {
+                               _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+                               continue;
+                       }
 
                        if (readlink(check_path, buf2, PATH_MAX) < 0)
                                continue;
index b2ac4155c446a3f5345f51815c3f42d73522997a..3a84274512e27b9bc095f5d2cc22140983150a8b 100644 (file)
@@ -125,7 +125,11 @@ int modules_init(void *data)
                if (dir->d_type != DT_REG)
                        continue;
 
-               snprintf(path, sizeof(path), "%s/%s", PLUGIN_PATH, dir->d_name);
+               if ((ret = snprintf(path, sizeof(path), "%s/%s", PLUGIN_PATH, dir->d_name)) > sizeof(path) - 1) {
+                       _E("Module path is longer than buffer. Need %d size of buffer.", ret + 1);
+                       continue;
+               }
+
                ret = storaged_open_module(path, &plugin);
                if (ret < 0) {
                        _E("Failed to open module(%s): %d", path, ret);