com php-src: Fixed bug #74883 SQLite3::__construct( ) produces "out of memory" exception with i nvalid flags: ext/sqlite3/sqlite3.c
| From: | Anatol Belski | Date: | Sat, 08 Jul 2017 21:52:22 +0000 |
| Subject: | com php-src: Fixed bug #74883 SQLite3::__construct( ) produces "out of memory" exception with i nvalid flags: ext/sqlite3/sqlite3.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-98463@lists.php.net to get a copy of this message | ||
Commit: b5338c0b7d145d9b5b5abcb9d695691ca5d6e418
Author: Anatol Belski <ab@php.net> Sat, 8 Jul 2017 23:52:22 +0200
Parents: 0fdceb6cd5eb4cc71eac68ca1a2037c32844a0f6
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b5338c0b7d145d9b5b5abcb9d695691ca5d6e418
Log:
Fixed bug #74883 SQLite3::__construct() produces "out of memory" exception with invalid
flags
Bugs:
https://bugs.php.net/74883
Changed paths:
M ext/sqlite3/sqlite3.c
Diff:
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index e3322dd..dcbc03c 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -103,6 +103,7 @@ PHP_METHOD(sqlite3, open)
char *filename, *encryption_key, *fullpath;
size_t filename_len, encryption_key_len = 0;
zend_long flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
+ int rc;
db_obj = Z_SQLITE3_DB_P(object);
@@ -141,11 +142,13 @@ PHP_METHOD(sqlite3, open)
}
#if SQLITE_VERSION_NUMBER >= 3005000
- if (sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL) != SQLITE_OK) {
+ rc = sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL);
#else
- if (sqlite3_open(fullpath, &(db_obj->db)) != SQLITE_OK) {
+ rc = sqlite3_open(fullpath, &(db_obj->db));
#endif
- zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s",
sqlite3_errmsg(db_obj->db));
+ if (rc != SQLITE_OK) {
+ zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s",
+ db_obj->db ? sqlite3_errmsg(db_obj->db) : sqlite3_errstr(rc));
if (fullpath != filename) {
efree(fullpath);
}