]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libebl: Don't blow up stack when processing large NT_GNU_ABI_TAG.
authorMark Wielaard <mjw@redhat.com>
Sun, 17 May 2015 18:07:56 +0000 (20:07 +0200)
committerMark Wielaard <mjw@redhat.com>
Wed, 27 May 2015 21:04:31 +0000 (23:04 +0200)
Normally an NT_GNU_ABI_TAG is large, just 4 words (16 bytes).
Only use stack allocated conversion buf for small (max 16 words) notes.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libebl/ChangeLog
libebl/eblobjnote.c

index 9ca7b47fa8335dad72ca3f3ebf3db1e9b30b5094..51ae60f2bbe08774706ab92feb2d5b1dd8baf470 100644 (file)
@@ -1,3 +1,8 @@
+2015-05-17  Mark Wielaard  <mjw@redhat.com>
+
+       * eblobjnote.c (ebl_object_note): If allocation buf is large, then
+       allocate it with malloc.
+
 2015-05-17  Mark Wielaard  <mjw@redhat.com>
 
        * eblopenbackend.c (MAX_PREFIX_LEN): New define (16).
index d1fe8210cf1b79dc55cf4de465f66559683514ce..b9bf1c0b9b92b5769bc0542adbe0a934054ff62d 100644 (file)
@@ -1,5 +1,5 @@
 /* Print contents of object file note.
-   Copyright (C) 2002, 2007, 2009, 2011 Red Hat, Inc.
+   Copyright (C) 2002, 2007, 2009, 2011, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -33,6 +33,7 @@
 
 #include <inttypes.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <libeblP.h>
 
@@ -165,7 +166,19 @@ ebl_object_note (ebl, name, type, descsz, desc)
                .d_size = descsz,
                .d_buf = (void *) desc
              };
-           uint32_t buf[descsz / 4];
+           /* Normally NT_GNU_ABI_TAG is just 4 words (16 bytes).  If it
+              is much (4*) larger dynamically allocate memory to convert.  */
+#define FIXED_TAG_BYTES 16
+           uint32_t sbuf[FIXED_TAG_BYTES];
+           uint32_t *buf;
+           if (unlikely (descsz / 4 > FIXED_TAG_BYTES))
+             {
+               buf = malloc (descsz);
+               if (unlikely (buf == NULL))
+                 return;
+             }
+           else
+             buf = sbuf;
            Elf_Data out =
              {
                .d_version = EV_CURRENT,
@@ -209,6 +222,8 @@ ebl_object_note (ebl, name, type, descsz, desc)
                  }
                putchar_unlocked ('\n');
              }
+           if (descsz / 4 > FIXED_TAG_BYTES)
+             free (buf);
            break;
          }
        /* FALLTHROUGH */