Bug #70862 [NEW]: Several functions do not check return code of php_stream_copy_to_mem()
| From: | fabian at tag1consulting dot com | Date: | Thu, 05 Nov 2015 15:20:29 +0000 |
| Subject: | Bug #70862 [NEW]: Several functions do not check return code of php_stream_copy_to_mem() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-197049@lists.php.net to get a copy of this message | ||
From: fabian at tag1consulting dot com
Operating system: Linux / Ubuntu
PHP version: 7.0Git-2015-11-05 (Git)
Package: Streams related
Bug Type: Bug
Bug description:Several functions do not check return code of php_stream_copy_to_mem()
Description:
------------
Follow-up to https://bugs.php.net/bug.php?id=70861 which had the
same
problem.
./ext/mbstring/mb_gpc.c
./ext/pdo_firebird/firebird_statement.c
./ext/pdo_mysql/mysql_statement.c
./ext/pdo_sqlite/sqlite_statement.c
./ext/sqlite3/sqlite3.c
./ext/standard/image.c
all have code similar to:
ZVAL_STR(parameter, php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL,
0));
in various variations.
However php_stream_copy_to_mem() can return NULL, which will make this
code fail under certain circumstances.
./ext/pdo/pdo_stmt.c has probably the best code for the problem to solve
in a generic way:
buf =
php_stream_copy_to_mem((php_stream*)value, PHP_STREAM_COPY_ALL, 0);
if (buf == NULL) {
ZVAL_EMPTY_STRING(dest);
} else {
ZVAL_STR(dest, buf);
}
and this likely should be made into a macro:
ZVAL_STR_OR_EMPTY(dest, buf, stream);
Expected result:
----------------
All functions should check the return value of php_stream_copy_to_mem()
Actual result:
--------------
Some function do not yet check the return value. This could lead to
bugs.
--
Edit bug report at https://bugs.php.net/bug.php?id=70862&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70862&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70862&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70862&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70862&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70862&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70862&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70862&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70862&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70862&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70862&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70862&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70862&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70862&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70862&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70862&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70862&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70862&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70862&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70862&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70862&r=mysqlcfg