This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Prevent a seg-fault in the assembler when provided with a bogus input source file.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e78bb25cb636a331f27e9cc4cba5522939567695

commit e78bb25cb636a331f27e9cc4cba5522939567695
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed May 3 09:52:01 2017 +0100

    Prevent a seg-fault in the assembler when provided with a bogus input source file.
    
    	PR gas/20941
    	* symbols.c (snapshot_symbol): Handle the case where
    	resolve_expression returns a local symbol.

Diff:
---
 gas/ChangeLog |  6 ++++++
 gas/symbols.c | 20 +++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 24155f1..ad3444b 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-03  Nick Clifton  <nickc@redhat.com>
+
+	PR gas/20941
+	* symbols.c (snapshot_symbol): Handle the case where
+	resolve_expression returns a local symbol.
+
 2017-05-02  Maciej W. Rozycki  <macro@imgtec.com>
 
 	* config/tc-mips.c (append_insn): Call `symbol_append' for any
diff --git a/gas/symbols.c b/gas/symbols.c
index 7146c7d..19a1fa5 100644
--- a/gas/symbols.c
+++ b/gas/symbols.c
@@ -1561,9 +1561,23 @@ snapshot_symbol (symbolS **symbolPP, valueT *valueP, segT *segP, fragS **fragPP)
 	}
 
       *symbolPP = symbolP;
-      *valueP = exp.X_add_number;
-      *segP = symbolP->bsym->section;
-      *fragPP = symbolP->sy_frag;
+
+      /* A bogus input file can result in resolve_expression()
+	 generating a local symbol, so we have to check again.  */
+      if (LOCAL_SYMBOL_CHECK (symbolP))
+	{
+	  struct local_symbol *locsym = (struct local_symbol *) symbolP;
+
+	  *valueP = locsym->lsy_value;
+	  *segP = locsym->lsy_section;
+	  *fragPP = local_symbol_get_frag (locsym);
+	}
+      else
+	{
+	  *valueP = exp.X_add_number;
+	  *segP = symbolP->bsym->section;
+	  *fragPP = symbolP->sy_frag;
+	}
 
       if (*segP == expr_section)
 	switch (exp.X_op)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]