Skip to content

Commit 8cdf00b

Browse files
Chun-Tse Shaoacmel
authored andcommitted
perf record: Fix a asan runtime error in util/maps.c
If I build perf with asan and run Zstd test: $ make -C tools/perf O=/tmp/perf DEBUG=1 EXTRA_CFLAGS="-O0 -g -fno-omit-frame-pointer -fsanitize=undefined" $ /tmp/perf/perf test "Zstd perf.data compression/decompression" -vv 83: Zstd perf.data compression/decompression: ... util/maps.c:1046:5: runtime error: null pointer passed as argument 2, which is declared to never be null ... The issue was caused by `bsearch`. The patch adds a check to ensure argument 2 and 3 are not NULL and 0. Testing with the commands above confirms that the runtime error is resolved. Reviewed-by: Ian Rogers <[email protected]> Signed-off-by: Chun-Tse Shao <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ben Gainey <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Nick Terrell <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 208c0e1 commit 8cdf00b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tools/perf/util/maps.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,13 @@ struct map *maps__find(struct maps *maps, u64 ip)
10821082
while (!done) {
10831083
down_read(maps__lock(maps));
10841084
if (maps__maps_by_address_sorted(maps)) {
1085-
struct map **mapp =
1086-
bsearch(&ip, maps__maps_by_address(maps), maps__nr_maps(maps),
1087-
sizeof(*mapp), map__addr_cmp);
1085+
struct map **mapp = NULL;
1086+
struct map **maps_by_address = maps__maps_by_address(maps);
1087+
unsigned int nr_maps = maps__nr_maps(maps);
10881088

1089+
if (maps_by_address && nr_maps)
1090+
mapp = bsearch(&ip, maps_by_address, nr_maps, sizeof(*mapp),
1091+
map__addr_cmp);
10891092
if (mapp)
10901093
result = map__get(*mapp);
10911094
done = true;

0 commit comments

Comments
 (0)