#35756 [NEW]: ecalloc in fgets() does't not check its return value

From: Date: Wed, 21 Dec 2005 02:39:47 +0000
Subject: #35756 [NEW]: ecalloc in fgets() does't not check its return value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-90772@lists.php.net to get a copy of this message
From: sqchen at citiz dot net Operating system: redhat 7.3 PHP version: 5.1.1 PHP Bug Type: Filesystem function related Bug description: ecalloc in fgets() does't not check its return value Description: ------------ file ext/standard/file.c line 1028 buf = ecalloc(len + 1, sizeof(char)); if (php_stream_get_line(stream, buf, len, &line_len) == NULL) { goto exit_failed; } here doesn't check the availablity of 'buf', so if ecalloc doesn't calloc a memory, it will return NULL, it will cause some problem Reproduce code: --------------- $fp=fopen("1.txt", "r"); fgets($fp, 2147483640); on some platform, when ecalloc failed, it will return NULL, so segmentation fault will prompt. the same as fread function -- Edit bug report at http://bugs.php.net/?id=35756&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35756&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35756&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35756&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=35756&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35756&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35756&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35756&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35756&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35756&r=support Expected behavior: http://bugs.php.net/fix.php?id=35756&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35756&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35756&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35756&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35756&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35756&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35756&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35756&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35756&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35756&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35756&r=mysqlcfg

« previous php.bugs (#90772) next »