diff options
author | Andrey Hristov <andrey@php.net> | 2010-05-26 07:28:43 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2010-05-26 07:28:43 +0000 |
commit | ce682f1b269c90f8c9a8ae37c394ea6b96c893a5 (patch) | |
tree | a46c330efaa07f37418e9eedccdb656a5359bd1b /ext/mysqli/php_mysqli_structs.h | |
parent | 89e93723fb11a623a42518d5de2c6f5e51243fda (diff) | |
download | php-git-ce682f1b269c90f8c9a8ae37c394ea6b96c893a5.tar.gz |
Add checks to check the underlying pointer in the resource.
It can happen that the underlying pointer is freed (like in
the case of connection reconnect), and then it cannot be allocated
anymore, which means that NULL will be used consequently by the
functions that fetch the resource and the crash is immediate.
Diffstat (limited to 'ext/mysqli/php_mysqli_structs.h')
-rw-r--r-- | ext/mysqli/php_mysqli_structs.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ext/mysqli/php_mysqli_structs.h b/ext/mysqli/php_mysqli_structs.h index baa173e34c..737641eace 100644 --- a/ext/mysqli/php_mysqli_structs.h +++ b/ext/mysqli/php_mysqli_structs.h @@ -296,6 +296,27 @@ PHP_MYSQLI_EXPORT(zend_object_value) mysqli_objects_new(zend_class_entry * TSRML } +#define MYSQLI_FETCH_RESOURCE_CONN(__ptr, __id, __check) \ +{ \ + MYSQLI_FETCH_RESOURCE((__ptr), MY_MYSQL *, (__id), "mysqli_link", (__check)); \ + if (!(__ptr)->mysql) { \ + mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \ + RETURN_NULL();\ + } \ +} + +#define MYSQLI_FETCH_RESOURCE_STMT(__ptr, __id, __check) \ +{ \ + MYSQLI_FETCH_RESOURCE((__ptr), MY_STMT *, (__id), "mysqli_stmt", (__check)); \ + if (!(__ptr)->stmt) { \ + mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\ + php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid object or resource %s\n", intern->zo.ce->name); \ + RETURN_NULL();\ + } \ +} + + #define MYSQLI_SET_STATUS(__id, __value) \ { \ mysqli_object *intern = (mysqli_object *)zend_object_store_get_object(*(__id) TSRMLS_CC);\ |