aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlex.l
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2016-12-05 16:00:43 +0000
committerNick Clifton <nickc@redhat.com>2016-12-05 16:00:43 +0000
commit406bd128dba2a59d0736839fc87a59bce319076c (patch)
tree8dd5ae1af0a3fd81b597df6c5c44d45b5e417952 /ld/ldlex.l
parent9b5481c63ab5e1e66e8f23681741039754eabcce (diff)
downloadgdb-406bd128dba2a59d0736839fc87a59bce319076c.zip
gdb-406bd128dba2a59d0736839fc87a59bce319076c.tar.gz
gdb-406bd128dba2a59d0736839fc87a59bce319076c.tar.bz2
Fix seg-fault in linker when passed a bogus input script.
PR ld/20906 * ldlex.l: Check for bogus strings in linker scripts.
Diffstat (limited to 'ld/ldlex.l')
-rw-r--r--ld/ldlex.l10
1 files changed, 8 insertions, 2 deletions
diff --git a/ld/ldlex.l b/ld/ldlex.l
index e1394a0..cd21c58 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -415,9 +415,15 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
<EXPRESSION,BOTH,SCRIPT,VERS_NODE,INPUTLIST>"\""[^\"]*"\"" {
/* No matter the state, quotes
- give what's inside */
+ give what's inside. */
+ bfd_size_type len;
yylval.name = xstrdup (yytext + 1);
- yylval.name[yyleng - 2] = 0;
+ /* PR ld/20906. A corrupt input file
+ can contain bogus strings. */
+ len = strlen (yylval.name);
+ if (len > yyleng - 2)
+ len = yyleng - 2;
+ yylval.name[len] = 0;
return NAME;
}
<BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}