summaryrefslogtreecommitdiffstats
path: root/libelf/elf_newscn.c
diff options
context:
space:
mode:
authorJakub Jelinek <[email protected]>2014-01-17 19:36:16 +0100
committerMark Wielaard <[email protected]>2014-01-23 11:31:53 +0100
commit720383c53b435de6647edd78060dd7d38ade25a5 (patch)
tree7437a0d1e3250ea4916f7caefdff05b218504510 /libelf/elf_newscn.c
parent58d3619facfb708f4998d73270ca4082b20853b9 (diff)
robustify: libelf.
Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libelf/elf_newscn.c')
-rw-r--r--libelf/elf_newscn.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/libelf/elf_newscn.c b/libelf/elf_newscn.c
index 70d29b66..6e0029ed 100644
--- a/libelf/elf_newscn.c
+++ b/libelf/elf_newscn.c
@@ -1,5 +1,5 @@
/* Append new section.
- Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2009, 2014 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper <[email protected]>, 1998.
@@ -83,10 +83,18 @@ elf_newscn (elf)
else
{
/* We must allocate a new element. */
- Elf_ScnList *newp;
+ Elf_ScnList *newp = NULL;
assert (elf->state.elf.scnincr > 0);
+ if (
+#if SIZE_MAX <= 4294967295U
+ likely (elf->state.elf.scnincr
+ < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList))
+#else
+ 1
+#endif
+ )
newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList)
+ ((elf->state.elf.scnincr *= 2)
* sizeof (Elf_Scn)), 1);