Skip to content

Commit

Permalink
Fix crasher in yocton_test.
Browse files Browse the repository at this point in the history
If we don't have an error, the error_msg variables points to an
unknown memory location and calling strstr() on it can cause a crash.
  • Loading branch information
fragglet committed Oct 27, 2023
1 parent 29eeb83 commit ea4752c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion yocton_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ int run_test_with_limit(char *filename, int alloc_limit)
fclose(fstream);

have_error = yocton_have_error(obj, &lineno, &error_msg);
if (alloc_limit != -1 && strstr(error_msg, ERROR_ALLOC) != NULL) {
if (alloc_limit != -1 && have_error
&& strstr(error_msg, ERROR_ALLOC) != NULL) {
// Perfectly normal to get a memory alloc error.
} else if (strcmp(output, error_data.expected_output) != 0) {
fprintf(stderr, "%s: wrong output, want:\n%s\ngot:\n%s\n",
Expand Down

0 comments on commit ea4752c

Please sign in to comment.