summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2015-02-10 10:19:56 +1100
committerTony Cook <tony@develop-help.com>2015-02-10 10:20:19 +1100
commit9efda33a86bb90e4838144d230a4fc3ae4d63d7d (patch)
tree003e95b5c0d03c0d022c11bc7686d49e824108cc /util.c
parent8a6d8ec6fe627c401c6c759edd38bbb10e4b56e9 (diff)
downloadperl-9efda33a86bb90e4838144d230a4fc3ae4d63d7d.tar.gz
[perl #123554] catch a couple of other size overflows
Unfortunately, running out of memory in safesysmalloc() and safesysrealloc() doesn't produce a catchable croak(), so remove the test.
Diffstat (limited to 'util.c')
-rw-r--r--util.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/util.c b/util.c
index 08f6abc395..c92ed2ee7d 100644
--- a/util.c
+++ b/util.c
@@ -128,7 +128,12 @@ Perl_safesysmalloc(MEM_SIZE size)
dTHX;
#endif
Malloc_t ptr;
+
+#ifdef USE_MDH
+ if (size + PERL_MEMORY_DEBUG_HEADER_SIZE < size)
+ goto out_of_memory;
size += PERL_MEMORY_DEBUG_HEADER_SIZE;
+#endif
#ifdef DEBUGGING
if ((SSize_t)size < 0)
Perl_croak_nocontext("panic: malloc, size=%"UVuf, (UV) size);
@@ -175,9 +180,7 @@ Perl_safesysmalloc(MEM_SIZE size)
}
else {
-#ifndef ALWAYS_NEED_THX
- dTHX;
-#endif
+ out_of_memory:
if (PL_nomemok)
ptr = NULL;
else
@@ -214,6 +217,8 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
else {
#ifdef USE_MDH
where = (Malloc_t)((char*)where-PERL_MEMORY_DEBUG_HEADER_SIZE);
+ if (size + PERL_MEMORY_DEBUG_HEADER_SIZE < size)
+ goto out_of_memory;
size += PERL_MEMORY_DEBUG_HEADER_SIZE;
{
struct perl_memory_debug_header *const header
@@ -292,9 +297,7 @@ Perl_safesysrealloc(Malloc_t where,MEM_SIZE size)
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) realloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
if (ptr == NULL) {
-#ifndef ALWAYS_NEED_THX
- dTHX;
-#endif
+ out_of_memory:
if (PL_nomemok)
ptr = NULL;
else