Skip to content

Commit

Permalink
Fix memory allocation size overflows (PR69687, patch by Marcel Böhme)
Browse files Browse the repository at this point in the history
	PR c++/69687
	* cplus-dem.c: Include <limits.h> if available.
	(INT_MAX): Define if necessary.
	(remember_type, remember_Ktype, register_Btype, string_need):
	Abort if we detect cases where we the size of the allocation would
	overflow.



git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234829 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
bernds committed Apr 8, 2016
1 parent 053ec22 commit b8106f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libiberty/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
2016-04-08 Marcel Böhme <boehme.marcel@gmail.com>

PR c++/69687
* cplus-dem.c: Include <limits.h> if available.
(INT_MAX): Define if necessary.
(remember_type, remember_Ktype, register_Btype, string_need):
Abort if we detect cases where we the size of the allocation would
overflow.

PR c++/70498
* cplus-dem.c (gnu_special): Handle case where consume_count returns
-1.
Expand Down
15 changes: 15 additions & 0 deletions libiberty/cplus-dem.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ void * malloc ();
void * realloc ();
#endif

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef INT_MAX
# define INT_MAX (int)(((unsigned int) ~0) >> 1) /* 0x7FFFFFFF */
#endif

#include <demangle.h>
#undef CURRENT_DEMANGLING_STYLE
#define CURRENT_DEMANGLING_STYLE work->options
Expand Down Expand Up @@ -4261,6 +4268,8 @@ remember_type (struct work_stuff *work, const char *start, int len)
}
else
{
if (work -> typevec_size > INT_MAX / 2)
xmalloc_failed (INT_MAX);
work -> typevec_size *= 2;
work -> typevec
= XRESIZEVEC (char *, work->typevec, work->typevec_size);
Expand Down Expand Up @@ -4288,6 +4297,8 @@ remember_Ktype (struct work_stuff *work, const char *start, int len)
}
else
{
if (work -> ksize > INT_MAX / 2)
xmalloc_failed (INT_MAX);
work -> ksize *= 2;
work -> ktypevec
= XRESIZEVEC (char *, work->ktypevec, work->ksize);
Expand Down Expand Up @@ -4317,6 +4328,8 @@ register_Btype (struct work_stuff *work)
}
else
{
if (work -> bsize > INT_MAX / 2)
xmalloc_failed (INT_MAX);
work -> bsize *= 2;
work -> btypevec
= XRESIZEVEC (char *, work->btypevec, work->bsize);
Expand Down Expand Up @@ -4771,6 +4784,8 @@ string_need (string *s, int n)
else if (s->e - s->p < n)
{
tem = s->p - s->b;
if (n > INT_MAX / 2 - tem)
xmalloc_failed (INT_MAX);
n += tem;
n *= 2;
s->b = XRESIZEVEC (char, s->b, n);
Expand Down

0 comments on commit b8106f5

Please sign in to comment.