Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a5b637

Browse files
committed
Merge branch 'pull-request/1091'
* pull-request/1091: Stop trying to call the callback after it has thrown an exception. Also, as an exception has been thrown, there is no need to have a separate error message. Fix freeing null segfault. Added test for behaviour. Conflicts: ext/sqlite3/tests/bug68760.phpt
2 parents 574b9a4 + 44f15b0 commit 5a5b637

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

ext/sqlite3/sqlite3.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,18 +860,23 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in
860860

861861
collation->fci.fci.params = zargs;
862862

863-
if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
864-
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
863+
if (!EG(exception)) {
864+
//Exception occurred on previous callback. Don't attempt to call function
865+
if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
866+
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
867+
}
865868
}
866869

867870
zval_ptr_dtor(&zargs[0]);
868871
zval_ptr_dtor(&zargs[1]);
869872
efree(zargs);
870873

871-
//retval ought to contain a ZVAL_LONG by now
872-
// (the result of a comparison, i.e. most likely -1, 0, or 1)
873-
//I suppose we could accept any scalar return type, though.
874-
if (Z_TYPE(retval) != IS_LONG){
874+
if (EG(exception)) {
875+
ret = 0;
876+
} else if (Z_TYPE(retval) != IS_LONG){
877+
//retval ought to contain a ZVAL_LONG by now
878+
// (the result of a comparison, i.e. most likely -1, 0, or 1)
879+
//I suppose we could accept any scalar return type, though.
875880
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback (invalid return type). Collation behaviour is undefined.");
876881
}else{
877882
ret = Z_LVAL(retval);

ext/sqlite3/tests/bug68760.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if (!extension_loaded('sqlite3')) die('skip');
77
--FILE--
88
<?php
99
function oopsFunction($a, $b) {
10-
echo "callback";
10+
echo "callback".PHP_EOL;
1111
throw new \Exception("oops");
1212
}
1313

@@ -31,6 +31,5 @@ catch(\Exception $e) {
3131
?>
3232
--EXPECTF--
3333
callback
34-
Warning: SQLite3::query(): An error occurred while invoking the compare callback in %a/bug68760.php on line %i
3534
Exception: oops
3635

0 commit comments

Comments
 (0)