Skip to content

Commit 27486a8

Browse files
andreasgerstmayracmel
authored andcommitted
perf script: Fix invalid read of directory entry after closedir()
closedir(lang_dir) frees the memory of script_dirent->d_name, which gets accessed in the next line in a call to scnprintf(). Valgrind report: Invalid read of size 1 ==413557== at 0x483CBE6: strlen (vg_replace_strmem.c:461) ==413557== by 0x4DD45FD: __vfprintf_internal (vfprintf-internal.c:1688) ==413557== by 0x4DE6679: __vsnprintf_internal (vsnprintf.c:114) ==413557== by 0x53A037: vsnprintf (stdio2.h:80) ==413557== by 0x53A037: scnprintf (vsprintf.c:21) ==413557== by 0x435202: get_script_path (builtin-script.c:3223) ==413557== Address 0x52e7313 is 1,139 bytes inside a block of size 32,816 free'd ==413557== at 0x483AA0C: free (vg_replace_malloc.c:540) ==413557== by 0x4E303C0: closedir (closedir.c:50) ==413557== by 0x4351DC: get_script_path (builtin-script.c:3222) Signed-off-by: Andreas Gerstmayr <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 1a4025f commit 27486a8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/builtin-script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,10 +3265,10 @@ static char *get_script_path(const char *script_root, const char *suffix)
32653265
__script_root = get_script_root(script_dirent, suffix);
32663266
if (__script_root && !strcmp(script_root, __script_root)) {
32673267
free(__script_root);
3268-
closedir(lang_dir);
32693268
closedir(scripts_dir);
32703269
scnprintf(script_path, MAXPATHLEN, "%s/%s",
32713270
lang_path, script_dirent->d_name);
3271+
closedir(lang_dir);
32723272
return strdup(script_path);
32733273
}
32743274
free(__script_root);

0 commit comments

Comments
 (0)