Fix illegal memory access bug in nm when run on a corrupt binary.
authorNick Clifton <nickc@redhat.com>
Mon, 13 Feb 2017 17:23:10 +0000 (17:23 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 13 Feb 2017 17:23:10 +0000 (17:23 +0000)
PR binutils/21150
* nm.c (file_symbol): Add test of string length before testing
string characters.

binutils/ChangeLog
binutils/nm.c

index 294e66ce44b7d0a9dc93515fe0839b1885c6f9cc..5baf48efa21f92854972d5238271e6b07c231567 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-13  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/21150
+       * nm.c (file_symbol): Add test of string length before testing
+       string characters.
+
 2017-02-13  Nick Clifton  <nickc@redhat.com>
 
        PR binutils/21135
index fcbab416f78a86081cd9aa346f17767b947751b1..7ddcc8a113d20e90e39314ed5dc8eebf1514cdbd 100644 (file)
@@ -685,7 +685,8 @@ size_forward1 (const void *P_x, const void *P_y)
 
 #define file_symbol(s, sn, snl)                        \
   (((s)->flags & BSF_FILE) != 0                        \
-   || ((sn)[(snl) - 2] == '.'                  \
+   || ((snl) > 2                               \
+       && (sn)[(snl) - 2] == '.'               \
        && ((sn)[(snl) - 1] == 'o'              \
           || (sn)[(snl) - 1] == 'a')))