Bug #73928 [NEW]: __zend_realloc doesn't respect len=0

From: Date: Fri, 13 Jan 2017 23:53:26 +0000
Subject: Bug #73928 [NEW]: __zend_realloc doesn't respect len=0
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206606@lists.php.net to get a copy of this message
From:             dev at pp3345 dot net
Operating system: Linux
PHP version:      7.1.0
Package:          Reproducible crash
Bug Type:         Bug
Bug description:__zend_realloc doesn't respect len=0

Description:
------------
According to man realloc, realloc() may return NULL if a valid pointer
and size=0 is passed, e. g. realloc(<ptr>, 0) is the same as
free(<ptr>). However, __zend_realloc always interprets NULL as OOM and
therefore bails out when trying to reallocate a pointer to size 0. For
example, mysqlnd sometimes calls erealloc(<ptr>, 0), which will crash
PHP when running with USE_ZEND_ALLOC=0.

From zend_alloc.c, lines 2834 - 2841:
ZEND_API void * __zend_realloc(void *p, size_t len)
{
	p = realloc(p, len);
	if (EXPECTED(p)) {
		return p;
	}
	zend_out_of_memory();
}

It should probably be something like if (EXPECTED(p) || !len).


-- 
Edit bug report at https://bugs.php.net/bug.php?id=73928&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73928&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73928&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73928&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73928&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73928&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73928&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73928&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73928&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73928&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73928&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73928&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73928&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73928&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73928&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73928&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73928&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73928&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73928&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73928&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73928&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#206606) next »