1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Give the SQLITE_TESTCTRL_PRNG_SEED two arguments. The second argument if not

NULL is a pointer to a database connection which seeds the connection from
its schema cookie.  In this way, fuzzers can control the PRNG seed.

FossilOrigin-Name: 49aa34480622cce4d7a72c59d9cfa8336886387acec8ee15b72f295ea1a52d8c
This commit is contained in:
drh
2019-08-03 01:39:20 +00:00
parent e6e96b1b45
commit 2e6d83bc49
9 changed files with 80 additions and 32 deletions

View File

@@ -3824,13 +3824,34 @@ int sqlite3_test_control(int op, ...){
break;
}
/* sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, unsigned int);
/* sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, int x, sqlite3 *db);
**
** Use the integer value as the seed for SQLite's internal PRNG.
** rather than the VFS xRandomness() function.
** Control the seed for the pseudo-random number generator (PRNG) that
** is built into SQLite. Cases:
**
** x!=0 && db!=0 Seed the PRNG to the current value of the
** schema cookie in the main database for db, or
** x if the schema cookie is zero. This case
** is convenient to use with database fuzzers
** as it allows the fuzzer some control over the
** the PRNG seed.
**
** x!=0 && db==0 Seed the PRNG to the value of x.
**
** x==0 && db==0 Revert to default behavior of using the
** xRandomness method on the primary VFS.
**
** This test-control also resets the PRNG so that the new seed will
** be used for the next call to sqlite3_randomness().
*/
case SQLITE_TESTCTRL_PRNG_SEED: {
sqlite3Config.iPrngSeed = va_arg(ap, unsigned int);
int x = va_arg(ap, int);
int y;
sqlite3 *db = va_arg(ap, sqlite3*);
assert( db==0 || db->aDb[0].pSchema!=0 );
if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
sqlite3Config.iPrngSeed = x;
sqlite3_randomness(0,0);
break;
}