History

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.

Ian Rogers committed 4 years ago

Commit caaaa551 parent 01b28e41 file · +6 −2Browse files

Unified · Split

tools/perf/tests/builtin-test.c+6−2
@@ -279,6 +279,7 @@ static const char *shell_test__description(char *description, size_t size, · 278 unmodified lines
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");
@@ -286,7 +287,9 @@ static const char *shell_test__description(char *description, size_t size, · 1 unmodified line
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, · 124 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t