Skip to content

Commit

Permalink
Address xRandomness error
Browse files Browse the repository at this point in the history
Fixes #526
  • Loading branch information
rogerbinns committed Jun 8, 2024
1 parent a9bd88a commit f34a8dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
19 changes: 19 additions & 0 deletions apsw/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5053,6 +5053,25 @@ def __init__(self, filename, flags):
self.assertTrue(vfs_saw_none)
self.assertTrue(vfsfile_saw_none)

def testIssue526(self):
"Error in VFS xRandomness"
class RandomVFS(apsw.VFS):
def __init__(self):
apsw.VFS.__init__(self, "issue526", "", 1)

vfs = RandomVFS()

self.db.pragma("journal_mode", "WAL")
try:
with self.db:
RandomVFS.xRandomness = lambda *args: 1/0
# this resets SQLite randomness so xRandonness of default VFS will be called again
apsw.randomness(0)
self.db.pragma("user_version", 1)
raise Exception("Should not reach here")
except ZeroDivisionError:
pass

def testCursorGet(self):
"Cursor.get"
for query, expected in (("select 3,4", (3, 4)), ("select 3; select 4", [3, 4]), ("select 3,4; select 4,5", [
Expand Down
7 changes: 7 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ history <https://devguide.python.org/versions/>`__.
APSW changes by version
-----------------------

next
====

Address how errors are handled in VFS xRandomness routine, that is
only called once by SQLite to seed its random number generator.
(:issue:`526`)

3.46.0.0
========

Expand Down
5 changes: 3 additions & 2 deletions src/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -4040,8 +4040,9 @@ static int connection_trace_and_exec(Connection *self, int release, int sp, int
PYSQLITE_CON_CALL(res = sqlite3_exec(self->db, sql, 0, 0, 0));
SET_EXC(res, self->db);
sqlite3_free(sql);
assert(res == SQLITE_OK || PyErr_Occurred());
return res == SQLITE_OK;

/* See issue 526 for why we can't trust SQLite success code */
return PyErr_Occurred() ? 0 : (res == SQLITE_OK);
}

static PyObject *
Expand Down

0 comments on commit f34a8dc

Please sign in to comment.