Skip to content

Commit 8a5bc8c

Browse files
committed
Fix mysqli_get_warnings() with multi queries
In this case warning_count may be non-zero, but php_get_warnings() may still return no warnings. In this case we should return false rather than returning a corrupted mysqli_warning object.
1 parent addc3c9 commit 8a5bc8c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ext/mysqli/mysqli_nonapi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ PHP_FUNCTION(mysqli_get_warnings)
973973
MY_MYSQL *mysql;
974974
zval *mysql_link;
975975
MYSQLI_RESOURCE *mysqli_resource;
976-
MYSQLI_WARNING *w;
976+
MYSQLI_WARNING *w = NULL;
977977

978978
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_link, mysqli_link_class_entry) == FAILURE) {
979979
return;
@@ -986,7 +986,8 @@ PHP_FUNCTION(mysqli_get_warnings)
986986
#else
987987
w = php_get_warnings(mysql->mysql);
988988
#endif
989-
} else {
989+
}
990+
if (!w) {
990991
RETURN_FALSE;
991992
}
992993
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));
@@ -1002,7 +1003,7 @@ PHP_FUNCTION(mysqli_stmt_get_warnings)
10021003
MY_STMT *stmt;
10031004
zval *stmt_link;
10041005
MYSQLI_RESOURCE *mysqli_resource;
1005-
MYSQLI_WARNING *w;
1006+
MYSQLI_WARNING *w = NULL;
10061007

10071008
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &stmt_link, mysqli_stmt_class_entry) == FAILURE) {
10081009
return;
@@ -1011,7 +1012,8 @@ PHP_FUNCTION(mysqli_stmt_get_warnings)
10111012

10121013
if (mysqli_stmt_warning_count(stmt->stmt)) {
10131014
w = php_get_warnings(mysqli_stmt_get_connection(stmt->stmt));
1014-
} else {
1015+
}
1016+
if (!w) {
10151017
RETURN_FALSE;
10161018
}
10171019
mysqli_resource = (MYSQLI_RESOURCE *)ecalloc (1, sizeof(MYSQLI_RESOURCE));

ext/mysqli/tests/bug54221.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ mysqli.reconnect = Off
4242
print "done!";
4343
?>
4444
--EXPECT--
45-
Warning: :
4645
Warning: 1050: Table 't54221' already exists
4746
done!

0 commit comments

Comments
 (0)