From 3d4143a38a374e092ff6e41b99549f05b5d6dcf0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 00:49:44 +0000 Subject: [PATCH 1/7] Do not try to eliminate No-ops at the end of VDBE program as this can cause problems for some DISTINCT handling algorithms, and does not improve performance. This also fixes an assertion fault found by libFuzzer. FossilOrigin-Name: 19d9f9ce691963310fa73ac5ff728ea8dea9d2b2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeaux.c | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 1ed1813193..164471ab97 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sobscure\smemory\sleak\sfound\sby\slibfuzzer\sthat\smay\soccur\sunder\ssome\scircumstances\sif\sexpanding\sa\s"*"\sexpression\scauses\sa\sSELECT\sto\sreturn\smore\sthan\s32767\scolumns. -D 2015-11-21T19:43:29.760 +C Do\snot\stry\sto\seliminate\sNo-ops\sat\sthe\send\sof\sVDBE\sprogram\sas\sthis\scan\scause\nproblems\sfor\ssome\sDISTINCT\shandling\salgorithms,\sand\sdoes\snot\simprove\nperformance.\s\sThis\salso\sfixes\san\sassertion\sfault\sfound\sby\slibFuzzer. +D 2015-11-24T00:49:44.712 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -406,7 +406,7 @@ F src/vdbe.c b56b2fc9b2f2d0a99d1dbd02d47efaacec253a4c F src/vdbe.h efb7a8c1459e31f3ea4377824c6a7e4cb5068637 F src/vdbeInt.h 75c2e82ee3357e9210c06474f8d9bdf12c81105d F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca -F src/vdbeaux.c b660c995256e3d3e2cb47ccd20b82a1c342fa093 +F src/vdbeaux.c 9a234c9aaab4ad725daf94667cfed441a437c52d F src/vdbeblob.c fdc4a81605ae7a35ae94a55bd768b66d6be16f15 F src/vdbemem.c fdd1578e47bea61390d472de53c565781d81e045 F src/vdbesort.c a7ec02da4494c59dfd071126dd3726be5a11459d @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 198d191b2f5ef7d63ac0093c701955c9052fd734 -R 8ed8d9e954ea81e19ae35a6836359b00 -U dan -Z f96d100152be981f85597b50bc9a8134 +P 60de5f23424552c98aa760ac89149a3d51f895be +R 22b08ad19af1727f96b09a8caa1d2b95 +U drh +Z 5e461470e8ebbd6a466d30753f42166b diff --git a/manifest.uuid b/manifest.uuid index 90fb983695..d9bf317509 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -60de5f23424552c98aa760ac89149a3d51f895be \ No newline at end of file +19d9f9ce691963310fa73ac5ff728ea8dea9d2b2 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 9ced9480b7..1889aec79f 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -837,7 +837,6 @@ void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){ freeP4(db, pOp->p4type, pOp->p4.p); memset(pOp, 0, sizeof(pOp[0])); pOp->opcode = OP_Noop; - if( addr==p->nOp-1 ) p->nOp--; } } From a9124d359b4fe798a0d1ed3531427c4012b1ff2e Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 24 Nov 2015 01:17:01 +0000 Subject: [PATCH 2/7] Add a clarifying comment to the virtual table test module 'test8'. FossilOrigin-Name: e92f97a6794440eb9d64e21218d39cb0e297a98e --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/test8.c | 7 +++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 164471ab97..7f76cef1ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\stry\sto\seliminate\sNo-ops\sat\sthe\send\sof\sVDBE\sprogram\sas\sthis\scan\scause\nproblems\sfor\ssome\sDISTINCT\shandling\salgorithms,\sand\sdoes\snot\simprove\nperformance.\s\sThis\salso\sfixes\san\sassertion\sfault\sfound\sby\slibFuzzer. -D 2015-11-24T00:49:44.712 +C Add\sa\sclarifying\scomment\sto\sthe\svirtual\stable\stest\smodule\s'test8'. +D 2015-11-24T01:17:01.246 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -356,7 +356,7 @@ F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e F src/test5.c 5a34feec76d9b3a86aab30fd4f6cc9c48cbab4c1 F src/test6.c 41cacf3b0dd180823919bf9e1fbab287c9266723 F src/test7.c 9c89a4f1ed6bb13af0ed805b8d782bd83fcd57e3 -F src/test8.c 610e3d523018ca63b08081795e76794a2121ec38 +F src/test8.c 697c9c84a13e08c72ea95a3637d4374caf54fc93 F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60 F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8 F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 60de5f23424552c98aa760ac89149a3d51f895be -R 22b08ad19af1727f96b09a8caa1d2b95 -U drh -Z 5e461470e8ebbd6a466d30753f42166b +P 19d9f9ce691963310fa73ac5ff728ea8dea9d2b2 +R 5f2e3f4f59d38b9500a642209d9901f8 +U mistachkin +Z 92cc12dd9fcb76285889b066a4a2f02e diff --git a/manifest.uuid b/manifest.uuid index d9bf317509..e7ce74a97f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -19d9f9ce691963310fa73ac5ff728ea8dea9d2b2 \ No newline at end of file +e92f97a6794440eb9d64e21218d39cb0e297a98e \ No newline at end of file diff --git a/src/test8.c b/src/test8.c index 2107710a99..7d3756aece 100644 --- a/src/test8.c +++ b/src/test8.c @@ -848,6 +848,13 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ case SQLITE_INDEX_CONSTRAINT_GE: zOp = ">="; break; case SQLITE_INDEX_CONSTRAINT_MATCH: + /* Purposely translate the MATCH operator into a LIKE, which + ** will be used by the next block of code to construct a new + ** query. It should also be noted here that the next block + ** of code requires the first letter of this operator to be + ** in upper-case to trigger the special MATCH handling (i.e. + ** wrapping the bound parameter with literal '%'s). + */ zOp = "LIKE"; break; } if( zOp[0]=='L' ){ From 2edc5fd73a9d98d7dabe896c01fa4b0438af25de Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 02:10:52 +0000 Subject: [PATCH 3/7] Remove an incorrect ALWAYS() macro. Fix for ticket [e5c6268dd807fa8950] - a problem introduced in SQLite 3.9.0 and found by libFuzzer. FossilOrigin-Name: 824ad96f72cb0c948ec98aca9d17a7e6790c575f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/expr.c | 2 +- test/distinct.test | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 7f76cef1ff..8f1d010fc6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sclarifying\scomment\sto\sthe\svirtual\stable\stest\smodule\s'test8'. -D 2015-11-24T01:17:01.246 +C Remove\san\sincorrect\sALWAYS()\smacro.\s\sFix\sfor\sticket\s[e5c6268dd807fa8950]\s-\s\na\sproblem\sintroduced\sin\sSQLite\s3.9.0\sand\sfound\sby\slibFuzzer. +D 2015-11-24T02:10:52.306 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -292,7 +292,7 @@ F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a F src/date.c fb1c99172017dcc8e237339132c91a21a0788584 F src/dbstat.c ffd63fc8ba7541476ced189b95e95d7f2bc63f78 F src/delete.c 00af9f08a15ddc5cba5962d3d3e5bf2d67b2e7da -F src/expr.c dfccb439a2a981d71970ce3d15effeb59b258798 +F src/expr.c cb1a419508e5b27769a91e00e36e94724e7b1d51 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 31900763094a3736a5fc887469202eb579fef2d0 F src/func.c ecdd69ec6a1e406f04cc73324be2ebbf6354197f @@ -579,7 +579,7 @@ F test/descidx1.test 6d03b44c8538fe0eb4924e19fba10cdd8f3c9240 F test/descidx2.test 9f1a0c83fd57f8667c82310ca21b30a350888b5d F test/descidx3.test 09ddbe3f5295f482d2f8b687cf6db8bad7acd9a2 F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e -F test/distinct.test 175d49ee783febaf368192dfe7f5afbc68910230 +F test/distinct.test a1783b960ad8c15a77cd9f207be072898db1026c F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376 F test/e_blobbytes.test 9bea1d3e2b20f3010b04abba58f6ba172301f49f F test/e_blobclose.test df756753f571bc30e42e3a6cba2807576e49e716 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 19d9f9ce691963310fa73ac5ff728ea8dea9d2b2 -R 5f2e3f4f59d38b9500a642209d9901f8 -U mistachkin -Z 92cc12dd9fcb76285889b066a4a2f02e +P e92f97a6794440eb9d64e21218d39cb0e297a98e +R 67e74267bda19ceddf30801e5b6dab85 +U drh +Z 988f4fae8dad66d5bbc6c477f18a57af diff --git a/manifest.uuid b/manifest.uuid index e7ce74a97f..3fce085be0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e92f97a6794440eb9d64e21218d39cb0e297a98e \ No newline at end of file +824ad96f72cb0c948ec98aca9d17a7e6790c575f \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 0255d6902f..8cf018f9d4 100644 --- a/src/expr.c +++ b/src/expr.c @@ -3818,7 +3818,7 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){ } return 2; } - if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){ + if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ if( pA->op==TK_FUNCTION ){ if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ diff --git a/test/distinct.test b/test/distinct.test index 2fb90dc3e3..dac2269b0b 100644 --- a/test/distinct.test +++ b/test/distinct.test @@ -252,4 +252,21 @@ do_execsql_test 5.6 { SELECT DISTINCT x FROM t1 ORDER BY x; } {1 2 3 4 5 6} +#------------------------------------------------------------------------- +# 2015-11-23. Problem discovered by Kostya Serebryany using libFuzzer +# +db close +sqlite3 db :memory: +do_execsql_test 6.1 { + CREATE TABLE jjj(x); + SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) + FROM sqlite_master; +} {jjj} +do_execsql_test 6.2 { + CREATE TABLE nnn(x); + SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) + FROM sqlite_master; +} {mmm} + + finish_test From 7060ef9294f2ec3e6eed0fac0e30952c46027f2c Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 03:50:16 +0000 Subject: [PATCH 4/7] Add a test case for the fix of check-in [19d9f9ce691963310] FossilOrigin-Name: 19a9c07b26a4123dc60abdcc84a956f88c352bab --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/hexlit.test | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 8f1d010fc6..d75d52e9d5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sincorrect\sALWAYS()\smacro.\s\sFix\sfor\sticket\s[e5c6268dd807fa8950]\s-\s\na\sproblem\sintroduced\sin\sSQLite\s3.9.0\sand\sfound\sby\slibFuzzer. -D 2015-11-24T02:10:52.306 +C Add\sa\stest\scase\sfor\sthe\sfix\sof\scheck-in\s[19d9f9ce691963310] +D 2015-11-24T03:50:16.891 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -761,7 +761,7 @@ F test/fuzzdata4.db 1882f0055fb63214d8407ddc7aca9b0b1c59af21 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hexlit.test 1d312fa816dfd3650a3bb488093bc09a0c927f67 +F test/hexlit.test d7b0a5f41123df1e43985b91b8b2e70f95282d21 F test/hidden.test 23c1393a79e846d68fd902d72c85d5e5dcf98711 F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P e92f97a6794440eb9d64e21218d39cb0e297a98e -R 67e74267bda19ceddf30801e5b6dab85 +P 824ad96f72cb0c948ec98aca9d17a7e6790c575f +R 9c18c36b835edbc9e97b6e63032cda67 U drh -Z 988f4fae8dad66d5bbc6c477f18a57af +Z babd8e22395e7e3423172e307e2f6983 diff --git a/manifest.uuid b/manifest.uuid index 3fce085be0..4c32ac931c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -824ad96f72cb0c948ec98aca9d17a7e6790c575f \ No newline at end of file +19a9c07b26a4123dc60abdcc84a956f88c352bab \ No newline at end of file diff --git a/test/hexlit.test b/test/hexlit.test index 2edd458e89..c48930b49b 100644 --- a/test/hexlit.test +++ b/test/hexlit.test @@ -109,6 +109,9 @@ do_execsql_test hexlit-301 { do_catchsql_test hexlist-400 { SELECT 0x10000000000000000; } {1 {hex literal too big: 0x10000000000000000}} +do_catchsql_test hexlist-401 { + SELECT DISTINCT 0x10000000000000000; +} {1 {hex literal too big: 0x10000000000000000}} do_catchsql_test hexlist-410 { DROP TABLE IF EXISTS t1; CREATE TABLE t1(x); From 6226ca2a6d33b2499fed9320d0d6319599bd8bc8 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 15:06:28 +0000 Subject: [PATCH 5/7] Make the geteuid() system call overloadable using xSetSystemCall() on the unix VFSes. FossilOrigin-Name: 6c2ddea65e1871b2fcb4991c5b3e6992993db3ea --- manifest | 14 ++++++------- manifest.uuid | 2 +- src/os_unix.c | 51 ++++++++++++++++++++++++++--------------------- test/syscall.test | 2 +- 4 files changed, 37 insertions(+), 32 deletions(-) diff --git a/manifest b/manifest index d75d52e9d5..2d0b9a58f6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\stest\scase\sfor\sthe\sfix\sof\scheck-in\s[19d9f9ce691963310] -D 2015-11-24T03:50:16.891 +C Make\sthe\sgeteuid()\ssystem\scall\soverloadable\susing\sxSetSystemCall()\son\sthe\nunix\sVFSes. +D 2015-11-24T15:06:28.338 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -323,7 +323,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c bddde71dc024574ace03ffee859abb99d152fd4a +F src/os_unix.c c5e7976c47cfd3134513ebfb2d140825d50e5275 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e @@ -1051,7 +1051,7 @@ F test/subtype1.test 7fe09496352f97053af1437150751be2d0a0cae8 F test/superlock.test 1cde669f68d2dd37d6c9bd35eee1d95491ae3fc2 F test/symlink.test 2513f7c030df0f435c6415687ba8b739f3d312df F test/sync.test a34cd43e98b7fb84eabbf38f7ed8f7349b3f3d85 -F test/syscall.test fba9ebdc6905d05bba6a835e691f20ed9ea2cc88 +F test/syscall.test 2aa9e111b79fb385681ff8940124def6f8faab87 F test/sysfault.test fa776e60bf46bdd3ae69f0b73e46ee3977a58ae6 F test/tabfunc01.test cc33684f9480fcf1fd5ce287ac28d22971cad1cc F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 824ad96f72cb0c948ec98aca9d17a7e6790c575f -R 9c18c36b835edbc9e97b6e63032cda67 +P 19a9c07b26a4123dc60abdcc84a956f88c352bab +R 02104466c6b651805702e9bf38bb181e U drh -Z babd8e22395e7e3423172e307e2f6983 +Z eddf0171a3f4a4814f215292a42ba620 diff --git a/manifest.uuid b/manifest.uuid index 4c32ac931c..ef64e4e41c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -19a9c07b26a4123dc60abdcc84a956f88c352bab \ No newline at end of file +6c2ddea65e1871b2fcb4991c5b3e6992993db3ea \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 4594e2d870..687baa107e 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -324,19 +324,6 @@ static int posixOpen(const char *zFile, int flags, int mode){ return open(zFile, flags, mode); } -/* -** On some systems, calls to fchown() will trigger a message in a security -** log if they come from non-root processes. So avoid calling fchown() if -** we are not running as root. -*/ -static int posixFchown(int fd, uid_t uid, gid_t gid){ -#if OS_VXWORKS - return 0; -#else - return geteuid() ? 0 : fchown(fd,uid,gid); -#endif -} - /* Forward reference */ static int openDirectory(const char*, int*); static int unixGetpagesize(void); @@ -423,7 +410,7 @@ static struct unix_syscall { #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ aSyscall[13].pCurrent) - { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, + { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE @@ -445,32 +432,50 @@ static struct unix_syscall { { "rmdir", (sqlite3_syscall_ptr)rmdir, 0 }, #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent) - { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 }, + { "fchown", (sqlite3_syscall_ptr)fchown, 0 }, #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent) + { "geteuid", (sqlite3_syscall_ptr)geteuid, 0 }, +#define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent) + #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0 { "mmap", (sqlite3_syscall_ptr)mmap, 0 }, -#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[21].pCurrent) +#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent) { "munmap", (sqlite3_syscall_ptr)munmap, 0 }, -#define osMunmap ((void*(*)(void*,size_t))aSyscall[22].pCurrent) +#define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent) #if HAVE_MREMAP { "mremap", (sqlite3_syscall_ptr)mremap, 0 }, #else { "mremap", (sqlite3_syscall_ptr)0, 0 }, #endif -#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[23].pCurrent) +#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent) + { "getpagesize", (sqlite3_syscall_ptr)unixGetpagesize, 0 }, -#define osGetpagesize ((int(*)(void))aSyscall[24].pCurrent) +#define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent) { "readlink", (sqlite3_syscall_ptr)readlink, 0 }, -#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[25].pCurrent) +#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent) #endif }; /* End of the overrideable system calls */ + +/* +** On some systems, calls to fchown() will trigger a message in a security +** log if they come from non-root processes. So avoid calling fchown() if +** we are not running as root. +*/ +static int robustFchown(int fd, uid_t uid, gid_t gid){ +#if OS_VXWORKS + return 0; +#else + return osGeteuid() ? 0 : osFchown(fd,uid,gid); +#endif +} + /* ** This is the xSetSystemCall() method of sqlite3_vfs for all of the ** "unix" VFSes. Return SQLITE_OK opon successfully updating the @@ -4343,7 +4348,7 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ ** is owned by the same user that owns the original database. Otherwise, ** the original owner will not be able to connect. */ - osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); + robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); /* Check to see if another process is holding the dead-man switch. ** If not, truncate the file to zero length. @@ -5827,7 +5832,7 @@ static int unixOpen( ** the same as the original database. */ if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){ - osFchown(fd, uid, gid); + robustFchown(fd, uid, gid); } } assert( fd>=0 ); @@ -7584,7 +7589,7 @@ int sqlite3_os_init(void){ /* Double-check that the aSyscall[] array has been constructed ** correctly. See ticket [bb3a86e890c8e96ab] */ - assert( ArraySize(aSyscall)==26 ); + assert( ArraySize(aSyscall)==27 ); /* Register all VFSes defined in the aVfs[] array */ for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){ diff --git a/test/syscall.test b/test/syscall.test index 83b8b8b40f..a935957d39 100644 --- a/test/syscall.test +++ b/test/syscall.test @@ -60,7 +60,7 @@ foreach s { open close access getcwd stat fstat ftruncate fcntl read pread write pwrite fchmod fallocate pread64 pwrite64 unlink openDirectory mkdir rmdir - statvfs fchown umask mmap munmap mremap + statvfs fchown geteuid umask mmap munmap mremap getpagesize readlink } { if {[test_syscall exists $s]} {lappend syscall_list $s} From aaeaa18e2e4ba3f82c4f11929f50fa9837d50e00 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 15:12:47 +0000 Subject: [PATCH 6/7] Fix a comment typo in the unix VFS. No changes to code. FossilOrigin-Name: 32e138796c66c88e8cbb77aa3a4282a38d1f959a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2d0b9a58f6..69d2b5459d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sthe\sgeteuid()\ssystem\scall\soverloadable\susing\sxSetSystemCall()\son\sthe\nunix\sVFSes. -D 2015-11-24T15:06:28.338 +C Fix\sa\scomment\stypo\sin\sthe\sunix\sVFS.\s\sNo\schanges\sto\scode. +D 2015-11-24T15:12:47.482 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -323,7 +323,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c c5e7976c47cfd3134513ebfb2d140825d50e5275 +F src/os_unix.c 3ca4a23db3ad0b809a0b8d7f879cf66f56b693d5 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 19a9c07b26a4123dc60abdcc84a956f88c352bab -R 02104466c6b651805702e9bf38bb181e +P 6c2ddea65e1871b2fcb4991c5b3e6992993db3ea +R 81ff6ba247633e5ac5ffc463969dd7f1 U drh -Z eddf0171a3f4a4814f215292a42ba620 +Z 2bab8f8a8131461afe24bb3f0bfc9cb2 diff --git a/manifest.uuid b/manifest.uuid index ef64e4e41c..501322045a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6c2ddea65e1871b2fcb4991c5b3e6992993db3ea \ No newline at end of file +32e138796c66c88e8cbb77aa3a4282a38d1f959a \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 687baa107e..768a2a9eec 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1104,7 +1104,7 @@ static unixInodeInfo *inodeList = 0; /* ** -** This function - unixLogError_x(), is only ever called via the macro +** This function - unixLogErrorAtLine(), is only ever called via the macro ** unixLogError(). ** ** It is invoked after an error occurs in an OS function and errno has been From 5a8d190b9ecf9e38857bfa77440a4e9c91aa28e3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 24 Nov 2015 16:40:23 +0000 Subject: [PATCH 7/7] Remove from os_unix.c pointless logic that tries to prevent a recurrence of a warning message that can only occur once. FossilOrigin-Name: 20256177072caa4f2b4114038ad1c8f6e26bc562 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 12 +----------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 69d2b5459d..36e5b27570 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scomment\stypo\sin\sthe\sunix\sVFS.\s\sNo\schanges\sto\scode. -D 2015-11-24T15:12:47.482 +C Remove\sfrom\sos_unix.c\spointless\slogic\sthat\stries\sto\sprevent\sa\srecurrence\sof\na\swarning\smessage\sthat\scan\sonly\soccur\sonce. +D 2015-11-24T16:40:23.118 F Makefile.in d828db6afa6c1fa060d01e33e4674408df1942a1 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e928e68168df69b353300ac87c10105206653a03 @@ -323,7 +323,7 @@ F src/os.c 8fd25588eeba74068d41102d26810e216999b6c8 F src/os.h 3e57a24e2794a94d3cf2342c6d9a884888cd96bf F src/os_common.h abdb9a191a367793268fe553d25bab894e986a0e F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa -F src/os_unix.c 3ca4a23db3ad0b809a0b8d7f879cf66f56b693d5 +F src/os_unix.c 80ec49758dbce979e4f89eda7695bbc01b0c4cd3 F src/os_win.c 386fba30419e8458b13209781c2af5590eab2811 F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 18341e2b759b447cbc82fb9215d08d9c5864e92e @@ -1404,7 +1404,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6c2ddea65e1871b2fcb4991c5b3e6992993db3ea -R 81ff6ba247633e5ac5ffc463969dd7f1 +P 32e138796c66c88e8cbb77aa3a4282a38d1f959a +R 39dda72890996a1a2961e4723fcfeb24 U drh -Z 2bab8f8a8131461afe24bb3f0bfc9cb2 +Z 6e0fb81bf9792119f74030230681d485 diff --git a/manifest.uuid b/manifest.uuid index 501322045a..9df0621fea 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -32e138796c66c88e8cbb77aa3a4282a38d1f959a \ No newline at end of file +20256177072caa4f2b4114038ad1c8f6e26bc562 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 768a2a9eec..82224053f0 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -258,8 +258,7 @@ static pid_t randomnessPid = 0; #define UNIXFILE_DELETE 0x20 /* Delete on close */ #define UNIXFILE_URI 0x40 /* Filename might have query parameters */ #define UNIXFILE_NOLOCK 0x80 /* Do no file locking */ -#define UNIXFILE_WARNED 0x0100 /* verifyDbFile() warnings issued */ -#define UNIXFILE_BLOCK 0x0200 /* Next SHM lock might block */ +#define UNIXFILE_BLOCK 0x0100 /* Next SHM lock might block */ /* ** Include code that is common to all os_*.c files @@ -1360,30 +1359,21 @@ static int fileHasMoved(unixFile *pFile){ static void verifyDbFile(unixFile *pFile){ struct stat buf; int rc; - if( pFile->ctrlFlags & UNIXFILE_WARNED ){ - /* One or more of the following warnings have already been issued. Do not - ** repeat them so as not to clutter the error log */ - return; - } rc = osFstat(pFile->h, &buf); if( rc!=0 ){ sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath); - pFile->ctrlFlags |= UNIXFILE_WARNED; return; } if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){ sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath); - pFile->ctrlFlags |= UNIXFILE_WARNED; return; } if( buf.st_nlink>1 ){ sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); - pFile->ctrlFlags |= UNIXFILE_WARNED; return; } if( fileHasMoved(pFile) ){ sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); - pFile->ctrlFlags |= UNIXFILE_WARNED; return; } }