com php-src: Fixed bug #69972 (Use-after-free vulnerability in sqlite3SafetyCheckSickOrOk()): ext/sqlite3/sqlite3.c ext/sqlite3/tests/bug69972.phpt

From: Date: Fri, 10 Jul 2015 00:27:28 +0000
Subject: com php-src: Fixed bug #69972 (Use-after-free vulnerability in sqlite3SafetyCheckSickOrOk()): ext/sqlite3/sqlite3.c ext/sqlite3/tests/bug69972.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87888@lists.php.net to get a copy of this message
Commit: 9cbe8610fa59d7716fb10ba88894091995d385f4 Author: Xinchen Hui <laruence@php.net> Tue, 7 Jul 2015 21:37:35 +0800 Committer: Ferenc Kovacs <tyrael@php.net> Fri, 10 Jul 2015 02:27:28 +0200 Parents: 1f4a84109549480a40b3c3b49456aa7bb4105bac Branches: PHP-5.6.11 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9cbe8610fa59d7716fb10ba88894091995d385f4 Log: Fixed bug #69972 (Use-after-free vulnerability in sqlite3SafetyCheckSickOrOk()) Bugs: https://bugs.php.net/69972 Changed paths: M ext/sqlite3/sqlite3.c A ext/sqlite3/tests/bug69972.phpt Diff: diff --git a/ext/sqlite3/sqlite3..c b/ext/sqlite3/sqlite3.c index 58ab5e8..16319a7 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -287,7 +287,11 @@ PHP_METHOD(sqlite3, lastErrorCode) return; } - RETURN_LONG(sqlite3_errcode(db_obj->db)); + if (db_obj->initialised) { + RETURN_LONG(sqlite3_errcode(db_obj->db)); + } else { + RETURN_LONG(0); + } } /* }}} */ @@ -305,7 +309,11 @@ PHP_METHOD(sqlite3, lastErrorMsg) return; } - RETVAL_STRING((char *)sqlite3_errmsg(db_obj->db), 1); + if (db_obj->initialised) { + RETURN_STRING((char *)sqlite3_errmsg(db_obj->db), 1); + } else { + RETURN_EMPTY_STRING(); + } } /* }}} */ diff --git a/ext/sqlite3/tests/bug69972.phpt b/ext/sqlite3/tests/bug69972.phpt new file mode 100644 index 0000000..539ebd2 --- /dev/null +++ b/ext/sqlite3/tests/bug69972.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #69972 (Use-after-free vulnerability in sqlite3SafetyCheckSickOrOk()) +--SKIPIF-- +<?php +if (!extension_loaded('sqlite3')) die('skip'); +?> +--FILE-- +<?php +$db = new SQLite3(':memory:'); +echo "SELECTING from invalid table\n"; +$result = $db->query("SELECT * FROM non_existent_table"); +echo "Closing database\n"; +var_dump($db->close()); +echo "Done\n"; + +// Trigger the use-after-free +echo "Error Code: " . $db->lastErrorCode() . "\n"; +echo "Error Msg: " . $db->lastErrorMsg() . "\n"; +?> +--EXPECTF-- +SELECTING from invalid table + +Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %sbug69972.php on line %d +Closing database +bool(true) +Done +Error Code: 0 +Error Msg:

« previous php.cvs (#87888) next »