diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-09 12:48:46 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-09 12:48:46 -0500 |
commit | 2e2bbc039fad9eabad6c4c1a473c8b2554cdd2d4 (patch) | |
tree | 8dec8139906e83b908c942788ff67eac800c23ca | |
parent | 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 (diff) |
perf tests: Avoid possible truncation with dirent->d_name + snprintf
Addressing a few cases spotted by a new warning in gcc 7:
tests/parse-events.c: In function 'test_pmu_events':
tests/parse-events.c:1790:39: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 90 [-Werror=format-truncation=]
snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name);
^~
In file included from /usr/include/stdio.h:939:0,
from /git/linux/tools/perf/util/map.h:9,
from /git/linux/tools/perf/util/symbol.h:7,
from /git/linux/tools/perf/util/evsel.h:10,
from tests/parse-events.c:3:
/usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 13 and 268 bytes into a destination of size 100
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests/parse-events.c:1798:29: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 100 [-Werror=format-truncation=]
snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name);
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Fixes: 945aea220bb8 ("perf tests: Move test objects into 'tests' directory")
Link: http://lkml.kernel.org/n/tip-ty4q2p8zp1dp3mskvubxskm5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/tests/parse-events.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 20c2e641c422..aa9276bfe3e9 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c | |||
@@ -1779,15 +1779,14 @@ static int test_pmu_events(void) | |||
1779 | } | 1779 | } |
1780 | 1780 | ||
1781 | while (!ret && (ent = readdir(dir))) { | 1781 | while (!ret && (ent = readdir(dir))) { |
1782 | #define MAX_NAME 100 | ||
1783 | struct evlist_test e; | 1782 | struct evlist_test e; |
1784 | char name[MAX_NAME]; | 1783 | char name[2 * NAME_MAX + 1 + 12 + 3]; |
1785 | 1784 | ||
1786 | /* Names containing . are special and cannot be used directly */ | 1785 | /* Names containing . are special and cannot be used directly */ |
1787 | if (strchr(ent->d_name, '.')) | 1786 | if (strchr(ent->d_name, '.')) |
1788 | continue; | 1787 | continue; |
1789 | 1788 | ||
1790 | snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name); | 1789 | snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name); |
1791 | 1790 | ||
1792 | e.name = name; | 1791 | e.name = name; |
1793 | e.check = test__checkevent_pmu_events; | 1792 | e.check = test__checkevent_pmu_events; |
@@ -1795,11 +1794,10 @@ static int test_pmu_events(void) | |||
1795 | ret = test_event(&e); | 1794 | ret = test_event(&e); |
1796 | if (ret) | 1795 | if (ret) |
1797 | break; | 1796 | break; |
1798 | snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name); | 1797 | snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name); |
1799 | e.name = name; | 1798 | e.name = name; |
1800 | e.check = test__checkevent_pmu_events_mix; | 1799 | e.check = test__checkevent_pmu_events_mix; |
1801 | ret = test_event(&e); | 1800 | ret = test_event(&e); |
1802 | #undef MAX_NAME | ||
1803 | } | 1801 | } |
1804 | 1802 | ||
1805 | closedir(dir); | 1803 | closedir(dir); |