Remove 'format-truncation' warning for GCC-9 21/220921/1
authorYunmi Ha <yunmi.ha@samsung.com>
Tue, 24 Dec 2019 07:07:50 +0000 (16:07 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Thu, 26 Dec 2019 02:32:14 +0000 (02:32 +0000)
Change-Id: I1ec0fe9415d76e0d6ce3539a7120fb0069e7f2b5
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
(cherry picked from commit c03c32c3891739fc4df0b2e97d8b7521e464d75d)

src/block/block.c
src/block/utils.c
src/core/modules.c

index 0c06b66..879fdf6 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 1c283ba..3588914 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 b2ac415..3a84274 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);