1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Avoid calling sqlite3_randomness and taking the PRNG mutex when writing a journal header in "journal_mode=memory" mode.

FossilOrigin-Name: c84e4483cb44f827416d8caafa22f076b2f31b2024fe8c5b5bcb0c9955149d11
This commit is contained in:
dan
2023-10-09 17:54:34 +00:00
parent 01a5a19919
commit 6c96bf2c3f
3 changed files with 32 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
C Add\sa\sTCL\sscript\sthat\sdoes\svarious\sverification\schecks\son\sthe\ssource\stree\nto\smake\ssure\sthat\sgenerated\scode\shas\sbeen\supdated\scorrectly.
D 2023-10-09T14:56:15.716
C Avoid\scalling\ssqlite3_randomness\sand\staking\sthe\sPRNG\smutex\swhen\swriting\sa\sjournal\sheader\sin\s"journal_mode=memory"\smode.
D 2023-10-09T17:54:34.805
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -701,7 +701,7 @@ F src/os_setup.h 6011ad7af5db4e05155f385eb3a9b4470688de6f65d6166b8956e58a3d87210
F src/os_unix.c 2e8b12107f75d1bd16412f312b4c5d5103191807a37836d3b81beb26436ad81b
F src/os_win.c 4a50a154aeebc66a1f8fb79c1ff6dd5fe3d005556533361e0d460d41cb6a45a8
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c 993445a19b611d473ca007542ab3149840661a4c7e9f2d9e1ec008b7cc2abe78
F src/pager.c bbd9b93c014679d8148235cc42b73bebda3f598d4f63a63cf7723ddf3087fd58
F src/pager.h f4d33fec8052603758792045493423b8871a996da2d0973927b7d36cd6070473
F src/parse.y aeb7760d41cfa86465e3adba506500c021597049fd55f82a30e5b7045862c28c
F src/pcache.c 040b165f30622a21b7a9a77c6f2e4877a32fb7f22d4c7f0d2a6fa6833a156a75
@@ -2128,8 +2128,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 7e8768bf8b4002b1c287f2bc95262548e2ae81b437936154f2bb1ea1f739a904
R 12c539e104384e89d6175d6c2ff0dac1
U drh
Z ea1222de532c1395014340ac1b27f9c9
P 1f1a358af77f4386f98010eeae8487e6d39548a6dfe58c2664552490e7661122
R cb97a01edd9563d34e6c8de016f82192
U dan
Z 70f60047d69ba97a07899a1fb54836c4
# Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
1f1a358af77f4386f98010eeae8487e6d39548a6dfe58c2664552490e7661122
c84e4483cb44f827416d8caafa22f076b2f31b2024fe8c5b5bcb0c9955149d11

View File

@@ -1492,9 +1492,32 @@ static int writeJournalHdr(Pager *pPager){
memset(zHeader, 0, sizeof(aJournalMagic)+4);
}
/* The random check-hash initializer */
if( pPager->journalMode!=PAGER_JOURNALMODE_MEMORY ){
sqlite3_randomness(sizeof(pPager->cksumInit), &pPager->cksumInit);
}
#ifdef SQLITE_DEBUG
else{
/* The Pager.cksumInit variable is usually randomized above to protect
** against there being existing records in the journal file. This is
** dangerous, as following a crash they may be mistaken for records
** written by the current transaction and rolled back into the database
** file, causing corruption. The following assert statements verify
** that this is not required in "journal_mode=memory" mode, as in that
** case the journal file is always 0 bytes in size at this point.
** It is advantageous to avoid the sqlite3_randomness() call if possible
** as it takes the global PRNG mutex. */
i64 sz = 0;
sqlite3OsFileSize(pPager->jfd, &sz);
assert( sz==0 );
assert( pPager->journalOff==journalHdrOffset(pPager) );
assert( sqlite3JournalIsInMemory(pPager->jfd) );
}
#endif
put32bits(&zHeader[sizeof(aJournalMagic)+4], pPager->cksumInit);
/* The initial database size */
put32bits(&zHeader[sizeof(aJournalMagic)+8], pPager->dbOrigSize);
/* The assumed sector size for this process */