Skip to content

Commit b5338c0

Browse files
committed
Fixed bug #74883 SQLite3::__construct() produces "out of memory" exception with invalid flags
1 parent 0fdceb6 commit b5338c0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ PHP_METHOD(sqlite3, open)
103103
char *filename, *encryption_key, *fullpath;
104104
size_t filename_len, encryption_key_len = 0;
105105
zend_long flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
106+
int rc;
106107

107108
db_obj = Z_SQLITE3_DB_P(object);
108109

@@ -141,11 +142,13 @@ PHP_METHOD(sqlite3, open)
141142
}
142143

143144
#if SQLITE_VERSION_NUMBER >= 3005000
144-
if (sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL) != SQLITE_OK) {
145+
rc = sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL);
145146
#else
146-
if (sqlite3_open(fullpath, &(db_obj->db)) != SQLITE_OK) {
147+
rc = sqlite3_open(fullpath, &(db_obj->db));
147148
#endif
148-
zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
149+
if (rc != SQLITE_OK) {
150+
zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s",
151+
db_obj->db ? sqlite3_errmsg(db_obj->db) : sqlite3_errstr(rc));
149152
if (fullpath != filename) {
150153
efree(fullpath);
151154
}

0 commit comments

Comments
 (0)