Fossil SCM
Update SQLite to the latest from the 3.8.2 branch.
Commit
2447b2d7ed9353a66e3d1abbf7cbdb95ea2af7dd
Parent
4699f8d9191a8cb…
2 files changed
+38
-17
+7
-5
+38
-17
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -135,11 +135,11 @@ | ||
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | -#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" | |
| 140 | +#define SQLITE_SOURCE_ID "2014-01-15 00:24:22 c697d2f83c2d8ea0a100b84b0debb6a322c3a876" | |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| @@ -2401,15 +2401,17 @@ | ||
| 2401 | 2401 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2402 | 2402 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2403 | 2403 | ** applications to access the same PRNG for other purposes. |
| 2404 | 2404 | ** |
| 2405 | 2405 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2406 | +** ^If N is less than one, then P can be a NULL pointer. | |
| 2406 | 2407 | ** |
| 2407 | -** ^The first time this routine is invoked (either internally or by | |
| 2408 | -** the application) the PRNG is seeded using randomness obtained | |
| 2409 | -** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2410 | -** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2408 | +** ^If this routine has not been previously called or if the previous | |
| 2409 | +** call had N less than one, then the PRNG is seeded using randomness | |
| 2410 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2411 | +** ^If the previous call to this routine had an N of 1 or more then | |
| 2412 | +** the pseudo-randomness is generated | |
| 2411 | 2413 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2412 | 2414 | ** method. |
| 2413 | 2415 | */ |
| 2414 | 2416 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2415 | 2417 | |
| @@ -12227,11 +12229,10 @@ | ||
| 12227 | 12229 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12228 | 12230 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12229 | 12231 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12230 | 12232 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12231 | 12233 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12232 | -SQLITE_PRIVATE void sqlite3PrngResetState(void); | |
| 12233 | 12234 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12234 | 12235 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12235 | 12236 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12236 | 12237 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12237 | 12238 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -20750,10 +20751,16 @@ | ||
| 20750 | 20751 | |
| 20751 | 20752 | #if SQLITE_THREADSAFE |
| 20752 | 20753 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20753 | 20754 | sqlite3_mutex_enter(mutex); |
| 20754 | 20755 | #endif |
| 20756 | + | |
| 20757 | + if( N<=0 ){ | |
| 20758 | + wsdPrng.isInit = 0; | |
| 20759 | + sqlite3_mutex_leave(mutex); | |
| 20760 | + return; | |
| 20761 | + } | |
| 20755 | 20762 | |
| 20756 | 20763 | /* Initialize the state of the random number generator once, |
| 20757 | 20764 | ** the first time this routine is called. The seed value does |
| 20758 | 20765 | ** not need to contain a lot of randomness since we are not |
| 20759 | 20766 | ** trying to do secure encryption or anything like that... |
| @@ -20778,19 +20785,20 @@ | ||
| 20778 | 20785 | wsdPrng.s[i] = t; |
| 20779 | 20786 | } |
| 20780 | 20787 | wsdPrng.isInit = 1; |
| 20781 | 20788 | } |
| 20782 | 20789 | |
| 20783 | - while( N-- ){ | |
| 20790 | + assert( N>0 ); | |
| 20791 | + do{ | |
| 20784 | 20792 | wsdPrng.i++; |
| 20785 | 20793 | t = wsdPrng.s[wsdPrng.i]; |
| 20786 | 20794 | wsdPrng.j += t; |
| 20787 | 20795 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20788 | 20796 | wsdPrng.s[wsdPrng.j] = t; |
| 20789 | 20797 | t += wsdPrng.s[wsdPrng.i]; |
| 20790 | 20798 | *(zBuf++) = wsdPrng.s[t]; |
| 20791 | - } | |
| 20799 | + }while( --N ); | |
| 20792 | 20800 | sqlite3_mutex_leave(mutex); |
| 20793 | 20801 | } |
| 20794 | 20802 | |
| 20795 | 20803 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20796 | 20804 | /* |
| @@ -20815,13 +20823,10 @@ | ||
| 20815 | 20823 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20816 | 20824 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20817 | 20825 | sizeof(sqlite3Prng) |
| 20818 | 20826 | ); |
| 20819 | 20827 | } |
| 20820 | -SQLITE_PRIVATE void sqlite3PrngResetState(void){ | |
| 20821 | - GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; | |
| 20822 | -} | |
| 20823 | 20828 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20824 | 20829 | |
| 20825 | 20830 | /************** End of random.c **********************************************/ |
| 20826 | 20831 | /************** Begin file utf.c *********************************************/ |
| 20827 | 20832 | /* |
| @@ -23355,10 +23360,16 @@ | ||
| 23355 | 23360 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23356 | 23361 | */ |
| 23357 | 23362 | char aPadding[32]; |
| 23358 | 23363 | #endif |
| 23359 | 23364 | }; |
| 23365 | + | |
| 23366 | +/* This variable holds the process id (pid) from when the xRandomness() | |
| 23367 | +** method was called. If xOpen() is called from a different process id, | |
| 23368 | +** indicating that a fork() has occurred, the PRNG will be reset. | |
| 23369 | +*/ | |
| 23370 | +static int randomnessPid = 0; | |
| 23360 | 23371 | |
| 23361 | 23372 | /* |
| 23362 | 23373 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23363 | 23374 | */ |
| 23364 | 23375 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -28944,10 +28955,20 @@ | ||
| 28944 | 28955 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 28945 | 28956 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 28946 | 28957 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 28947 | 28958 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 28948 | 28959 | ); |
| 28960 | + | |
| 28961 | + /* Detect a pid change and reset the PRNG. There is a race condition | |
| 28962 | + ** here such that two or more threads all trying to open databases at | |
| 28963 | + ** the same instant might all reset the PRNG. But multiple resets | |
| 28964 | + ** are harmless. | |
| 28965 | + */ | |
| 28966 | + if( randomnessPid!=getpid() ){ | |
| 28967 | + randomnessPid = getpid(); | |
| 28968 | + sqlite3_randomness(0,0); | |
| 28969 | + } | |
| 28949 | 28970 | |
| 28950 | 28971 | memset(p, 0, sizeof(unixFile)); |
| 28951 | 28972 | |
| 28952 | 28973 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 28953 | 28974 | UnixUnusedFd *pUnused; |
| @@ -29332,22 +29353,22 @@ | ||
| 29332 | 29353 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29333 | 29354 | ** that we always use the same random number sequence. This makes the |
| 29334 | 29355 | ** tests repeatable. |
| 29335 | 29356 | */ |
| 29336 | 29357 | memset(zBuf, 0, nBuf); |
| 29358 | + randomnessPid = getpid(); | |
| 29337 | 29359 | #if !defined(SQLITE_TEST) |
| 29338 | 29360 | { |
| 29339 | - int pid, fd, got; | |
| 29361 | + int fd, got; | |
| 29340 | 29362 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29341 | 29363 | if( fd<0 ){ |
| 29342 | 29364 | time_t t; |
| 29343 | 29365 | time(&t); |
| 29344 | 29366 | memcpy(zBuf, &t, sizeof(t)); |
| 29345 | - pid = getpid(); | |
| 29346 | - memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); | |
| 29347 | - assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); | |
| 29348 | - nBuf = sizeof(t) + sizeof(pid); | |
| 29367 | + memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); | |
| 29368 | + assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); | |
| 29369 | + nBuf = sizeof(t) + sizeof(randomnessPid); | |
| 29349 | 29370 | }else{ |
| 29350 | 29371 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29351 | 29372 | robust_close(0, fd, __LINE__); |
| 29352 | 29373 | } |
| 29353 | 29374 | } |
| @@ -122094,11 +122115,11 @@ | ||
| 122094 | 122115 | ** Reset the PRNG back to its uninitialized state. The next call |
| 122095 | 122116 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 122096 | 122117 | ** to the xRandomness method of the default VFS. |
| 122097 | 122118 | */ |
| 122098 | 122119 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 122099 | - sqlite3PrngResetState(); | |
| 122120 | + sqlite3_randomness(0,0); | |
| 122100 | 122121 | break; |
| 122101 | 122122 | } |
| 122102 | 122123 | |
| 122103 | 122124 | /* |
| 122104 | 122125 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| 122105 | 122126 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -135,11 +135,11 @@ | |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -2401,15 +2401,17 @@ | |
| 2401 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2402 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2403 | ** applications to access the same PRNG for other purposes. |
| 2404 | ** |
| 2405 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2406 | ** |
| 2407 | ** ^The first time this routine is invoked (either internally or by |
| 2408 | ** the application) the PRNG is seeded using randomness obtained |
| 2409 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2410 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2411 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2412 | ** method. |
| 2413 | */ |
| 2414 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2415 | |
| @@ -12227,11 +12229,10 @@ | |
| 12227 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12228 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12229 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12230 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12231 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12232 | SQLITE_PRIVATE void sqlite3PrngResetState(void); |
| 12233 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12234 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12235 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12236 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12237 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -20750,10 +20751,16 @@ | |
| 20750 | |
| 20751 | #if SQLITE_THREADSAFE |
| 20752 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20753 | sqlite3_mutex_enter(mutex); |
| 20754 | #endif |
| 20755 | |
| 20756 | /* Initialize the state of the random number generator once, |
| 20757 | ** the first time this routine is called. The seed value does |
| 20758 | ** not need to contain a lot of randomness since we are not |
| 20759 | ** trying to do secure encryption or anything like that... |
| @@ -20778,19 +20785,20 @@ | |
| 20778 | wsdPrng.s[i] = t; |
| 20779 | } |
| 20780 | wsdPrng.isInit = 1; |
| 20781 | } |
| 20782 | |
| 20783 | while( N-- ){ |
| 20784 | wsdPrng.i++; |
| 20785 | t = wsdPrng.s[wsdPrng.i]; |
| 20786 | wsdPrng.j += t; |
| 20787 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20788 | wsdPrng.s[wsdPrng.j] = t; |
| 20789 | t += wsdPrng.s[wsdPrng.i]; |
| 20790 | *(zBuf++) = wsdPrng.s[t]; |
| 20791 | } |
| 20792 | sqlite3_mutex_leave(mutex); |
| 20793 | } |
| 20794 | |
| 20795 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20796 | /* |
| @@ -20815,13 +20823,10 @@ | |
| 20815 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20816 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20817 | sizeof(sqlite3Prng) |
| 20818 | ); |
| 20819 | } |
| 20820 | SQLITE_PRIVATE void sqlite3PrngResetState(void){ |
| 20821 | GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; |
| 20822 | } |
| 20823 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20824 | |
| 20825 | /************** End of random.c **********************************************/ |
| 20826 | /************** Begin file utf.c *********************************************/ |
| 20827 | /* |
| @@ -23355,10 +23360,16 @@ | |
| 23355 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23356 | */ |
| 23357 | char aPadding[32]; |
| 23358 | #endif |
| 23359 | }; |
| 23360 | |
| 23361 | /* |
| 23362 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23363 | */ |
| 23364 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -28944,10 +28955,20 @@ | |
| 28944 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 28945 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 28946 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 28947 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 28948 | ); |
| 28949 | |
| 28950 | memset(p, 0, sizeof(unixFile)); |
| 28951 | |
| 28952 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 28953 | UnixUnusedFd *pUnused; |
| @@ -29332,22 +29353,22 @@ | |
| 29332 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29333 | ** that we always use the same random number sequence. This makes the |
| 29334 | ** tests repeatable. |
| 29335 | */ |
| 29336 | memset(zBuf, 0, nBuf); |
| 29337 | #if !defined(SQLITE_TEST) |
| 29338 | { |
| 29339 | int pid, fd, got; |
| 29340 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29341 | if( fd<0 ){ |
| 29342 | time_t t; |
| 29343 | time(&t); |
| 29344 | memcpy(zBuf, &t, sizeof(t)); |
| 29345 | pid = getpid(); |
| 29346 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 29347 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 29348 | nBuf = sizeof(t) + sizeof(pid); |
| 29349 | }else{ |
| 29350 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29351 | robust_close(0, fd, __LINE__); |
| 29352 | } |
| 29353 | } |
| @@ -122094,11 +122115,11 @@ | |
| 122094 | ** Reset the PRNG back to its uninitialized state. The next call |
| 122095 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 122096 | ** to the xRandomness method of the default VFS. |
| 122097 | */ |
| 122098 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 122099 | sqlite3PrngResetState(); |
| 122100 | break; |
| 122101 | } |
| 122102 | |
| 122103 | /* |
| 122104 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| 122105 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -135,11 +135,11 @@ | |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | #define SQLITE_SOURCE_ID "2014-01-15 00:24:22 c697d2f83c2d8ea0a100b84b0debb6a322c3a876" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -2401,15 +2401,17 @@ | |
| 2401 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2402 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2403 | ** applications to access the same PRNG for other purposes. |
| 2404 | ** |
| 2405 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2406 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2407 | ** |
| 2408 | ** ^If this routine has not been previously called or if the previous |
| 2409 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2410 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2411 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2412 | ** the pseudo-randomness is generated |
| 2413 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2414 | ** method. |
| 2415 | */ |
| 2416 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2417 | |
| @@ -12227,11 +12229,10 @@ | |
| 12229 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12230 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12231 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12232 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12233 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12234 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12235 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12236 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12237 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12238 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -20750,10 +20751,16 @@ | |
| 20751 | |
| 20752 | #if SQLITE_THREADSAFE |
| 20753 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20754 | sqlite3_mutex_enter(mutex); |
| 20755 | #endif |
| 20756 | |
| 20757 | if( N<=0 ){ |
| 20758 | wsdPrng.isInit = 0; |
| 20759 | sqlite3_mutex_leave(mutex); |
| 20760 | return; |
| 20761 | } |
| 20762 | |
| 20763 | /* Initialize the state of the random number generator once, |
| 20764 | ** the first time this routine is called. The seed value does |
| 20765 | ** not need to contain a lot of randomness since we are not |
| 20766 | ** trying to do secure encryption or anything like that... |
| @@ -20778,19 +20785,20 @@ | |
| 20785 | wsdPrng.s[i] = t; |
| 20786 | } |
| 20787 | wsdPrng.isInit = 1; |
| 20788 | } |
| 20789 | |
| 20790 | assert( N>0 ); |
| 20791 | do{ |
| 20792 | wsdPrng.i++; |
| 20793 | t = wsdPrng.s[wsdPrng.i]; |
| 20794 | wsdPrng.j += t; |
| 20795 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20796 | wsdPrng.s[wsdPrng.j] = t; |
| 20797 | t += wsdPrng.s[wsdPrng.i]; |
| 20798 | *(zBuf++) = wsdPrng.s[t]; |
| 20799 | }while( --N ); |
| 20800 | sqlite3_mutex_leave(mutex); |
| 20801 | } |
| 20802 | |
| 20803 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20804 | /* |
| @@ -20815,13 +20823,10 @@ | |
| 20823 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20824 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20825 | sizeof(sqlite3Prng) |
| 20826 | ); |
| 20827 | } |
| 20828 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20829 | |
| 20830 | /************** End of random.c **********************************************/ |
| 20831 | /************** Begin file utf.c *********************************************/ |
| 20832 | /* |
| @@ -23355,10 +23360,16 @@ | |
| 23360 | ** it is larger than the struct CrashFile defined in test6.c. |
| 23361 | */ |
| 23362 | char aPadding[32]; |
| 23363 | #endif |
| 23364 | }; |
| 23365 | |
| 23366 | /* This variable holds the process id (pid) from when the xRandomness() |
| 23367 | ** method was called. If xOpen() is called from a different process id, |
| 23368 | ** indicating that a fork() has occurred, the PRNG will be reset. |
| 23369 | */ |
| 23370 | static int randomnessPid = 0; |
| 23371 | |
| 23372 | /* |
| 23373 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23374 | */ |
| 23375 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| @@ -28944,10 +28955,20 @@ | |
| 28955 | assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB |
| 28956 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 28957 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 28958 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 28959 | ); |
| 28960 | |
| 28961 | /* Detect a pid change and reset the PRNG. There is a race condition |
| 28962 | ** here such that two or more threads all trying to open databases at |
| 28963 | ** the same instant might all reset the PRNG. But multiple resets |
| 28964 | ** are harmless. |
| 28965 | */ |
| 28966 | if( randomnessPid!=getpid() ){ |
| 28967 | randomnessPid = getpid(); |
| 28968 | sqlite3_randomness(0,0); |
| 28969 | } |
| 28970 | |
| 28971 | memset(p, 0, sizeof(unixFile)); |
| 28972 | |
| 28973 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 28974 | UnixUnusedFd *pUnused; |
| @@ -29332,22 +29353,22 @@ | |
| 29353 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29354 | ** that we always use the same random number sequence. This makes the |
| 29355 | ** tests repeatable. |
| 29356 | */ |
| 29357 | memset(zBuf, 0, nBuf); |
| 29358 | randomnessPid = getpid(); |
| 29359 | #if !defined(SQLITE_TEST) |
| 29360 | { |
| 29361 | int fd, got; |
| 29362 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29363 | if( fd<0 ){ |
| 29364 | time_t t; |
| 29365 | time(&t); |
| 29366 | memcpy(zBuf, &t, sizeof(t)); |
| 29367 | memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); |
| 29368 | assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); |
| 29369 | nBuf = sizeof(t) + sizeof(randomnessPid); |
| 29370 | }else{ |
| 29371 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29372 | robust_close(0, fd, __LINE__); |
| 29373 | } |
| 29374 | } |
| @@ -122094,11 +122115,11 @@ | |
| 122115 | ** Reset the PRNG back to its uninitialized state. The next call |
| 122116 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 122117 | ** to the xRandomness method of the default VFS. |
| 122118 | */ |
| 122119 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 122120 | sqlite3_randomness(0,0); |
| 122121 | break; |
| 122122 | } |
| 122123 | |
| 122124 | /* |
| 122125 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| 122126 |
+7
-5
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -107,11 +107,11 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.8.2" |
| 111 | 111 | #define SQLITE_VERSION_NUMBER 3008002 |
| 112 | -#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" | |
| 112 | +#define SQLITE_SOURCE_ID "2014-01-15 00:24:22 c697d2f83c2d8ea0a100b84b0debb6a322c3a876" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -2373,15 +2373,17 @@ | ||
| 2373 | 2373 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2374 | 2374 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2375 | 2375 | ** applications to access the same PRNG for other purposes. |
| 2376 | 2376 | ** |
| 2377 | 2377 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2378 | +** ^If N is less than one, then P can be a NULL pointer. | |
| 2378 | 2379 | ** |
| 2379 | -** ^The first time this routine is invoked (either internally or by | |
| 2380 | -** the application) the PRNG is seeded using randomness obtained | |
| 2381 | -** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2382 | -** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2380 | +** ^If this routine has not been previously called or if the previous | |
| 2381 | +** call had N less than one, then the PRNG is seeded using randomness | |
| 2382 | +** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2383 | +** ^If the previous call to this routine had an N of 1 or more then | |
| 2384 | +** the pseudo-randomness is generated | |
| 2383 | 2385 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2384 | 2386 | ** method. |
| 2385 | 2387 | */ |
| 2386 | 2388 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2387 | 2389 | |
| 2388 | 2390 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.2" |
| 111 | #define SQLITE_VERSION_NUMBER 3008002 |
| 112 | #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -2373,15 +2373,17 @@ | |
| 2373 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2374 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2375 | ** applications to access the same PRNG for other purposes. |
| 2376 | ** |
| 2377 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2378 | ** |
| 2379 | ** ^The first time this routine is invoked (either internally or by |
| 2380 | ** the application) the PRNG is seeded using randomness obtained |
| 2381 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2382 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2383 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2384 | ** method. |
| 2385 | */ |
| 2386 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2387 | |
| 2388 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -107,11 +107,11 @@ | |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.2" |
| 111 | #define SQLITE_VERSION_NUMBER 3008002 |
| 112 | #define SQLITE_SOURCE_ID "2014-01-15 00:24:22 c697d2f83c2d8ea0a100b84b0debb6a322c3a876" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -2373,15 +2373,17 @@ | |
| 2373 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2374 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2375 | ** applications to access the same PRNG for other purposes. |
| 2376 | ** |
| 2377 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2378 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2379 | ** |
| 2380 | ** ^If this routine has not been previously called or if the previous |
| 2381 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2382 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2383 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2384 | ** the pseudo-randomness is generated |
| 2385 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2386 | ** method. |
| 2387 | */ |
| 2388 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2389 | |
| 2390 |