gas: segmentation fault in as_report_context
Alan Modra
amodra@gmail.com
Wed Jan 28 08:14:29 GMT 2026
After input_scrub_end when next_saved_file is NULL, it is possible
that macro_nest will be non-zero on files with errors. If
output_file_close then has an error and reports it with as_fatal we
hit the segfault.
PR 33746
* input_scrub.c (as_report_context): Don't assume
next_saved_file is non-NULL.
(as_where): Likewise.
diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index ae393b66e6f..2ccc2ce9c8e 100644
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -531,14 +531,14 @@ new_logical_line (const char *fname, int line_number)
void
as_report_context (void)
{
- const struct input_save *saved = next_saved_file;
+ const struct input_save *saved;
enum expansion expansion = from_sb_expansion;
int indent = 1;
if (!macro_nest)
return;
- do
+ for (saved = next_saved_file; saved; saved = saved->next_saved_file)
{
if (expansion != expanding_macro)
/* Nothing. */;
@@ -553,7 +553,6 @@ as_report_context (void)
expansion = saved->from_sb_expansion;
++indent;
}
- while ((saved = saved->next_saved_file) != NULL);
}
/* Return the current physical input file name and line number, if known */
@@ -583,10 +582,10 @@ as_where (unsigned int *linep)
if (macro_nest && is_linefile)
{
- const struct input_save *saved = next_saved_file;
+ const struct input_save *saved;
enum expansion expansion = from_sb_expansion;
- do
+ for (saved = next_saved_file; saved; saved = saved->next_saved_file)
{
if (expansion != expanding_macro)
/* Nothing. */;
@@ -606,7 +605,6 @@ as_where (unsigned int *linep)
expansion = saved->from_sb_expansion;
}
- while ((saved = saved->next_saved_file) != NULL);
}
return file;
--
Alan Modra
More information about the Binutils
mailing list