]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
readprofile: add scanf field width limits [cppcheck]
authorBoris Egorov <egorov@linux.com>
Tue, 19 Jan 2016 05:45:15 +0000 (11:45 +0600)
committerBoris Egorov <egorov@linux.com>
Tue, 19 Jan 2016 06:59:12 +0000 (12:59 +0600)
[sys-utils/readprofile.c:301]: (warning) scanf without field width limits can crash with huge input data.
[sys-utils/readprofile.c:322]: (warning) scanf without field width limits can crash with huge input data.

sys-utils/readprofile.c

index 3ba866e24ed697c30a95f4794d440fc748204d76..39a24deda353d6984d7a09cb333a2384a80e5d4d 100644 (file)
@@ -298,7 +298,7 @@ int main(int argc, char **argv)
                err(EXIT_FAILURE, "%s", mapFile);
 
        while (fgets(mapline, S_LEN, map)) {
-               if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
+               if (sscanf(mapline, "%llx %7[^\n ] %127[^\n ]", &fn_add, mode, fn_name) != 3)
                        errx(EXIT_FAILURE, _("%s(%i): wrong map line"), mapFile,
                             maplineno);
                /* only elf works like this */
@@ -319,7 +319,7 @@ int main(int argc, char **argv)
                unsigned int this = 0;
                int done = 0;
 
-               if (sscanf(mapline, "%llx %s %s", &next_add, mode, next_name) != 3)
+               if (sscanf(mapline, "%llx %7[^\n ] %127[^\n ]", &next_add, mode, next_name) != 3)
                        errx(EXIT_FAILURE, _("%s(%i): wrong map line"), mapFile,
                             maplineno);
                header_printed = 0;