Fix unbounded stack usage warning inside the SAFE_BYTE_GET macro.
authorNick Clifton <nickc@redhat.com>
Tue, 22 Mar 2016 13:25:22 +0000 (13:25 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 22 Mar 2016 13:25:22 +0000 (13:25 +0000)
PR 19851
binutils * dwarf.c (SAFE_BYTE_GET): Replace local dynamic array allocation
with run time size check.

binutils/ChangeLog
binutils/dwarf.c

index 0694a58c5495ec133047d8f7d50e64abf6cd0edf..75d7170f5c324e45a782cce0467062670adf06cf 100644 (file)
@@ -1,5 +1,9 @@
 2016-03-22  Nick Clifton  <nickc@redhat.com>
 
+       PR 19851
+       * dwarf.c (SAFE_BYTE_GET): Replace local dynamic array allocation
+       with run time size check.
+
        * configure: Regenerate.
 
 2016-03-21  Andrew Burgess  <andrew.burgess@embecosm.com>
index 85d18f3b004357fad3efed5ecf50bbc54ef8197b..086df4b4ba64099b94ff914035308387c49344bc 100644 (file)
@@ -317,8 +317,13 @@ read_uleb128 (unsigned char * data,
 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END)   \
   do                                           \
     {                                          \
-      int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
       unsigned int amount = (AMOUNT);          \
+      if (sizeof (VAL) < amount)               \
+       {                                       \
+         error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
+                amount, (int) sizeof (VAL));   \
+         amount = sizeof (VAL);                \
+       }                                       \
       if (((PTR) + amount) >= (END))           \
        {                                       \
          if ((PTR) < (END))                    \