6732063
diff -up avr-binutils-2.23.2/binutils-2.23.2/libiberty/objalloc.c.orig avr-binutils-2.23.2/binutils-2.23.2/libiberty/objalloc.c
6732063
--- avr-binutils-2.23.2/binutils-2.23.2/libiberty/objalloc.c.orig	2014-02-03 16:36:15.635819681 +0100
6732063
+++ avr-binutils-2.23.2/binutils-2.23.2/libiberty/objalloc.c	2014-02-03 16:36:18.820803899 +0100
6732063
@@ -1,5 +1,5 @@
6732063
 /* objalloc.c -- routines to allocate memory for objects
6732063
-   Copyright 1997 Free Software Foundation, Inc.
6732063
+   Copyright 1997-2012 Free Software Foundation, Inc.
6732063
    Written by Ian Lance Taylor, Cygnus Solutions.
6732063
 
6732063
 This program is free software; you can redistribute it and/or modify it
6732063
@@ -112,8 +112,10 @@ objalloc_create (void)
6732063
 /* Allocate space from an objalloc structure.  */
6732063
 
6732063
 PTR
6732063
-_objalloc_alloc (struct objalloc *o, unsigned long len)
6732063
+_objalloc_alloc (struct objalloc *o, unsigned long original_len)
6732063
 {
6732063
+  unsigned long len = original_len;
6732063
+
6732063
   /* We avoid confusion from zero sized objects by always allocating
6732063
      at least 1 byte.  */
6732063
   if (len == 0)
6732063
@@ -121,6 +123,11 @@ _objalloc_alloc (struct objalloc *o, uns
6732063
 
6732063
   len = (len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1);
6732063
 
6732063
+  /* Check for overflow in the alignment operation above and the
6732063
+     malloc argument below. */
6732063
+  if (len + CHUNK_HEADER_SIZE < original_len)
6732063
+    return NULL;
6732063
+
6732063
   if (len <= o->current_space)
6732063
     {
6732063
       o->current_ptr += len;