[binutils-gdb] gas: segmentation fault in as_report_context
Alan Modra
amodra@sourceware.org
Wed Jan 28 08:14:57 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ea96771a0188a235645558ae10d6885c91c1ac00
commit ea96771a0188a235645558ae10d6885c91c1ac00
Author: Alan Modra <amodra@gmail.com>
Date: Wed Jan 28 18:08:09 2026 +1030
gas: segmentation fault in as_report_context
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:
---
gas/input-scrub.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
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;
More information about the Binutils-cvs
mailing list