Skip to content

Commit 9a734c5

Browse files
committed
Implement NUL byte checks for dbnames
Since we're passing these parameter to C functions accepting `char*` without any further checking, we should reject strings with NUL bytes in the first place.
1 parent 8a66cb3 commit 9a734c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,11 @@ PHP_METHOD(sqlite3, openBlob)
13001300
return;
13011301
}
13021302

1303+
if (ZEND_NUM_ARGS() >= 4 && CHECK_NULL_PATH(dbname, dbname_len)) {
1304+
zend_value_error("dbname must not contain NUL bytes");
1305+
return;
1306+
}
1307+
13031308
sqlite_flags = (flags & SQLITE_OPEN_READWRITE) ? 1 : 0;
13041309

13051310
if (sqlite3_blob_open(db_obj->db, dbname, table, column, rowid, sqlite_flags, &blob) != SQLITE_OK) {
@@ -1368,6 +1373,13 @@ PHP_METHOD(sqlite3, backup)
13681373
return;
13691374
}
13701375

1376+
if ((ZEND_NUM_ARGS() >= 2 && CHECK_NULL_PATH(source_dbname, source_dbname_length))
1377+
|| (ZEND_NUM_ARGS() >= 3 && CHECK_NULL_PATH(destination_dbname, destination_dbname_length))
1378+
) {
1379+
zend_value_error("dbname must not contain NUL bytes");
1380+
return;
1381+
}
1382+
13711383
destination_obj = Z_SQLITE3_DB_P(destination_zval);
13721384

13731385
SQLITE3_CHECK_INITIALIZED(destination_obj, destination_obj->initialised, SQLite3)

0 commit comments

Comments
 (0)