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.
Unified · Split
| @@ -279,6 +279,7 @@ static const char *shell_test__description(char *description, size_t size, · 278 unmodified lines | |||
| 279 | { | 279 | { |
| 280 | FILE *fp; | 280 | FILE *fp; |
| 281 | char filename[PATH_MAX]; | 281 | char filename[PATH_MAX]; |
| 282 | int ch; | ||
| 282 | 283 | ||
| 283 | path__join(filename, sizeof(filename), path, name); | 284 | path__join(filename, sizeof(filename), path, name); |
| 284 | fp = fopen(filename, "r"); | 285 | fp = fopen(filename, "r"); |
| @@ -286,7 +287,9 @@ static const char *shell_test__description(char *description, size_t size, · 1 unmodified line | |||
| 286 | return NULL; | 287 | return NULL; |
| 287 | 288 | ||
| 288 | /* Skip shebang */ | 289 | /* Skip shebang */ |
| 289 | while (fgetc(fp) != '\n'); | 290 | do { |
| 291 | ch = fgetc(fp); | ||
| 292 | } while (ch != EOF && ch != '\n'); | ||
| 290 | 293 | ||
| 291 | description = fgets(description, size, fp); | 294 | description = fgets(description, size, fp); |
| 292 | fclose(fp); | 295 | fclose(fp); |
| @@ -417,7 +420,8 @@ static int run_shell_tests(int argc, const char *argv[], int i, int width, · 124 unmodified lines | |||
| 417 | .priv = &st, | 420 | .priv = &st, |
| 418 | }; | 421 | }; |
| 419 | 422 | ||
| 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)) | ||
| 421 | continue; | 425 | continue; |
| 422 | 426 | ||
| 423 | st.file = ent->d_name; | 427 | st.file = ent->d_name; |