[SV 65324] disable_builtins: Don't dereference NULL suffix_file

Make crashes when -r and MAKEFLAGS= are specified on the command line.

On startup make begins to process command line arguments.
During processing of "MAKEFLAGS=" make calls reset_makeflags, which in
turn calls disable_builtins, which dereferences null suffix_file.
Here is the backtrace.

0 disable_builtins main.c:3482
1 reset_makeflags main.c:3104
2 set_special_var variable.c:1325
3 do_variable_definition variable.c:1693
4 try_variable_definition variable.c:1889
5 handle_non_switch_argument main.c:3021
6 decode_switches main.c:3150
7 main main.c:1621

* src/main.c (disable_builtins): Avoid dereferencing null suffix_file.
* tests/scripts/features/suffixrules: Add a test.
This commit is contained in:
Dmitry Goncharov 2024-04-21 13:34:12 -04:00 committed by Paul Smith
parent f7985ab827
commit 40664fef1f
2 changed files with 8 additions and 1 deletions

View file

@ -3473,7 +3473,7 @@ void disable_builtins ()
if (no_builtin_rules_flag && ! old_builtin_rules_flag)
{
old_builtin_rules_flag = 1;
if (suffix_file->builtin)
if (suffix_file && suffix_file->builtin)
{
free_dep_chain (suffix_file->deps);
suffix_file->deps = 0;

View file

@ -178,5 +178,12 @@ MAKEFLAGS += -r
unlink('hello.c', 'hello.o');
# sv 65324.
# Crash in disable_builtins.
run_make_test(q!
all:;
!, '-r MAKEFLAGS=', "#MAKE#: 'all' is up to date.\n");
# Complete
1;