summaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2019-03-11 10:45:01 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-03-11 15:33:19 -0400
commit905e4aff31382c3f9b2014d1361f4a1be4479ba2 (patch)
tree3f1f3cf123f08ce46f432cb3f4fa6219390356ae /tools/perf/builtin-script.c
parentca52babe033f2a0a535ce7c814e54a44cead1f15 (diff)
perf script: Add array bound checking to list_scripts
Don't overflow array when the scripts directory is too large, or the script file name is too long. Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20190311144502.15423-11-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b695b20ffc8a..2f93d60c5a17 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2982,7 +2982,8 @@ static int check_ev_match(char *dir_name, char *scriptname,
2982 * will list all statically runnable scripts, select one, execute it and 2982 * will list all statically runnable scripts, select one, execute it and
2983 * show the output in a perf browser. 2983 * show the output in a perf browser.
2984 */ 2984 */
2985int find_scripts(char **scripts_array, char **scripts_path_array) 2985int find_scripts(char **scripts_array, char **scripts_path_array, int num,
2986 int pathlen)
2986{ 2987{
2987 struct dirent *script_dirent, *lang_dirent; 2988 struct dirent *script_dirent, *lang_dirent;
2988 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN]; 2989 char scripts_path[MAXPATHLEN], lang_path[MAXPATHLEN];
@@ -3027,7 +3028,10 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
3027 /* Skip those real time scripts: xxxtop.p[yl] */ 3028 /* Skip those real time scripts: xxxtop.p[yl] */
3028 if (strstr(script_dirent->d_name, "top.")) 3029 if (strstr(script_dirent->d_name, "top."))
3029 continue; 3030 continue;
3030 sprintf(scripts_path_array[i], "%s/%s", lang_path, 3031 if (i >= num)
3032 break;
3033 snprintf(scripts_path_array[i], pathlen, "%s/%s",
3034 lang_path,
3031 script_dirent->d_name); 3035 script_dirent->d_name);
3032 temp = strchr(script_dirent->d_name, '.'); 3036 temp = strchr(script_dirent->d_name, '.');
3033 snprintf(scripts_array[i], 3037 snprintf(scripts_array[i],