Skip to content

Commit cde32be

Browse files
authored
sqlite3: fix internal return type violation in escapeString() (#22026)
If this call fails due to an internal libsqlite3 error, then the function will return NULL (as that's the default value set by the VM). However, the function is marked with a non-nullable string return type. Therefore this will result in a type violation and a fatal error in debug mode. Either we solve it by making the function nullable or throw. I chose the latter as it is less of a footgun.
1 parent 0078a27 commit cde32be

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

ext/sqlite3/sqlite3.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ PHP_METHOD(SQLite3, escapeString)
478478
if (ret) {
479479
RETVAL_STRING(ret);
480480
sqlite3_free(ret);
481+
} else {
482+
zend_throw_exception_ex(php_sqlite3_exception_ce, 0, "Unable to escape string");
483+
RETURN_THROWS();
481484
}
482485
} else {
483486
RETURN_EMPTY_STRING();

0 commit comments

Comments
 (0)