Skip to content

Commit caaaa55

Browse files
captain5050acmel
authored andcommitted
perf test: Avoid shell test description infinite loop
for_each_shell_test() is already strict in expecting tests to be files and executable. It is sometimes possible when it iterates over all files that it finds one that is executable and lacks a newline character. When this happens the loop never terminates as it doesn't check for EOF. Add the EOF check to make this loop at least bounded by the file size. If the description is returned as NULL then also skip the test. Signed-off-by: Ian Rogers <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Marco Elver <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Riccardo Mancini <[email protected]> Cc: Sohaib Mohamed <[email protected]> Cc: Stephane Eranian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 01b28e4 commit caaaa55

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/perf/tests/builtin-test.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,17 @@ static const char *shell_test__description(char *description, size_t size,
279279
{
280280
FILE *fp;
281281
char filename[PATH_MAX];
282+
int ch;
282283

283284
path__join(filename, sizeof(filename), path, name);
284285
fp = fopen(filename, "r");
285286
if (!fp)
286287
return NULL;
287288

288289
/* Skip shebang */
289-
while (fgetc(fp) != '\n');
290+
do {
291+
ch = fgetc(fp);
292+
} while (ch != EOF && ch != '\n');
290293

291294
description = fgets(description, size, fp);
292295
fclose(fp);
@@ -417,7 +420,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width,
417420
.priv = &st,
418421
};
419422

420-
if (!perf_test__matches(test_suite.desc, curr, argc, argv))
423+
if (test_suite.desc == NULL ||
424+
!perf_test__matches(test_suite.desc, curr, argc, argv))
421425
continue;
422426

423427
st.file = ent->d_name;

0 commit comments

Comments
 (0)