Skip to content

Commit ab368bb

Browse files
committed
sqlite3: fix internal return type violation in escapeString()
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 ef589ce commit ab368bb

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
@@ -494,6 +494,9 @@ PHP_METHOD(SQLite3, escapeString)
494494
if (ret) {
495495
RETVAL_STRING(ret);
496496
sqlite3_free(ret);
497+
} else {
498+
zend_throw_exception_ex(php_sqlite3_exception_ce, 0, "Unable to escape string");
499+
RETURN_THROWS();
497500
}
498501
} else {
499502
RETURN_EMPTY_STRING();

0 commit comments

Comments
 (0)