Fossil SCM

Disable triggers using SQLITE_DBCONFIG_ENABLE_TRIGGERS for defense in depth. SQLite 3.35.0 is required due to Fossil's use of TEMP triggers. Also, use the new RETURNING clause for queries where it makes sense, again requiring SQLite 3.35.0.

drh 2021-02-03 14:23 trunk
Commit 8a3dc1a9754e5fec28c9b52bbbca6e94fff980798fb9136abe793ed1739e3638
+3 -7
--- src/alerts.c
+++ src/alerts.c
@@ -1377,11 +1377,10 @@
13771377
&& subscribe_error_check(&eErr,&zErr,needCaptcha)
13781378
){
13791379
/* A validated request for a new subscription has been received. */
13801380
char ssub[20];
13811381
const char *zEAddr = P("e");
1382
- sqlite3_int64 id; /* New subscriber Id */
13831382
const char *zCode; /* New subscriber code (in hex) */
13841383
int nsub = 0;
13851384
const char *suname = PT("suname");
13861385
if( suname==0 && needCaptcha==0 && !g.perm.Admin ) suname = g.zLogin;
13871386
if( suname && suname[0]==0 ) suname = 0;
@@ -1390,25 +1389,22 @@
13901389
if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
13911390
if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
13921391
if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
13931392
if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x';
13941393
ssub[nsub] = 0;
1395
- db_multi_exec(
1394
+ zCode = db_text(0,
13961395
"INSERT INTO subscriber(semail,suname,"
13971396
" sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1398
- "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
1397
+ "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1398
+ "RETURNING hex(subscriberCode);",
13991399
/* semail */ zEAddr,
14001400
/* suname */ suname,
14011401
/* sverified */ needCaptcha==0,
14021402
/* sdigest */ PB("di"),
14031403
/* ssub */ ssub,
14041404
/* smip */ g.zIpAddr
14051405
);
1406
- id = db_last_insert_rowid();
1407
- zCode = db_text(0,
1408
- "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1409
- id);
14101406
if( !needCaptcha ){
14111407
/* The new subscription has been added on behalf of a logged-in user.
14121408
** No verification is required. Jump immediately to /alerts page.
14131409
*/
14141410
if( g.perm.Admin ){
14151411
--- src/alerts.c
+++ src/alerts.c
@@ -1377,11 +1377,10 @@
1377 && subscribe_error_check(&eErr,&zErr,needCaptcha)
1378 ){
1379 /* A validated request for a new subscription has been received. */
1380 char ssub[20];
1381 const char *zEAddr = P("e");
1382 sqlite3_int64 id; /* New subscriber Id */
1383 const char *zCode; /* New subscriber code (in hex) */
1384 int nsub = 0;
1385 const char *suname = PT("suname");
1386 if( suname==0 && needCaptcha==0 && !g.perm.Admin ) suname = g.zLogin;
1387 if( suname && suname[0]==0 ) suname = 0;
@@ -1390,25 +1389,22 @@
1390 if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1391 if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1392 if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1393 if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x';
1394 ssub[nsub] = 0;
1395 db_multi_exec(
1396 "INSERT INTO subscriber(semail,suname,"
1397 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1398 "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
 
1399 /* semail */ zEAddr,
1400 /* suname */ suname,
1401 /* sverified */ needCaptcha==0,
1402 /* sdigest */ PB("di"),
1403 /* ssub */ ssub,
1404 /* smip */ g.zIpAddr
1405 );
1406 id = db_last_insert_rowid();
1407 zCode = db_text(0,
1408 "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1409 id);
1410 if( !needCaptcha ){
1411 /* The new subscription has been added on behalf of a logged-in user.
1412 ** No verification is required. Jump immediately to /alerts page.
1413 */
1414 if( g.perm.Admin ){
1415
--- src/alerts.c
+++ src/alerts.c
@@ -1377,11 +1377,10 @@
1377 && subscribe_error_check(&eErr,&zErr,needCaptcha)
1378 ){
1379 /* A validated request for a new subscription has been received. */
1380 char ssub[20];
1381 const char *zEAddr = P("e");
 
1382 const char *zCode; /* New subscriber code (in hex) */
1383 int nsub = 0;
1384 const char *suname = PT("suname");
1385 if( suname==0 && needCaptcha==0 && !g.perm.Admin ) suname = g.zLogin;
1386 if( suname && suname[0]==0 ) suname = 0;
@@ -1390,25 +1389,22 @@
1389 if( g.perm.RdForum && PB("sf") ) ssub[nsub++] = 'f';
1390 if( g.perm.RdTkt && PB("st") ) ssub[nsub++] = 't';
1391 if( g.perm.RdWiki && PB("sw") ) ssub[nsub++] = 'w';
1392 if( g.perm.RdForum && PB("sx") ) ssub[nsub++] = 'x';
1393 ssub[nsub] = 0;
1394 zCode = db_text(0,
1395 "INSERT INTO subscriber(semail,suname,"
1396 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1397 "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1398 "RETURNING hex(subscriberCode);",
1399 /* semail */ zEAddr,
1400 /* suname */ suname,
1401 /* sverified */ needCaptcha==0,
1402 /* sdigest */ PB("di"),
1403 /* ssub */ ssub,
1404 /* smip */ g.zIpAddr
1405 );
 
 
 
 
1406 if( !needCaptcha ){
1407 /* The new subscription has been added on behalf of a logged-in user.
1408 ** No verification is required. Jump immediately to /alerts page.
1409 */
1410 if( g.perm.Admin ){
1411
+1
--- src/db.c
+++ src/db.c
@@ -1618,10 +1618,11 @@
16181618
if( rc!=SQLITE_OK ){
16191619
db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
16201620
}
16211621
db_maybe_set_encryption_key(db, zDbName);
16221622
sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, 0, &rc);
1623
+ sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, 0, &rc);
16231624
sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
16241625
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
16251626
sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
16261627
sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
16271628
sqlite3_busy_timeout(db, 15000);
16281629
--- src/db.c
+++ src/db.c
@@ -1618,10 +1618,11 @@
1618 if( rc!=SQLITE_OK ){
1619 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
1620 }
1621 db_maybe_set_encryption_key(db, zDbName);
1622 sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, 0, &rc);
 
1623 sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
1624 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
1625 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
1626 sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
1627 sqlite3_busy_timeout(db, 15000);
1628
--- src/db.c
+++ src/db.c
@@ -1618,10 +1618,11 @@
1618 if( rc!=SQLITE_OK ){
1619 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
1620 }
1621 db_maybe_set_encryption_key(db, zDbName);
1622 sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_FKEY, 0, &rc);
1623 sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_TRIGGER, 0, &rc);
1624 sqlite3_db_config(db, SQLITE_DBCONFIG_TRUSTED_SCHEMA, 0, &rc);
1625 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DDL, 0, &rc);
1626 sqlite3_db_config(db, SQLITE_DBCONFIG_DQS_DML, 0, &rc);
1627 sqlite3_db_config(db, SQLITE_DBCONFIG_DEFENSIVE, 1, &rc);
1628 sqlite3_busy_timeout(db, 15000);
1629
+3 -7
--- src/login.c
+++ src/login.c
@@ -1667,11 +1667,10 @@
16671667
login_set_user_cookie(zUserID, uid, NULL, 0);
16681668
if( doAlerts ){
16691669
/* Also make the new user a subscriber. */
16701670
Blob hdr, body;
16711671
AlertSender *pSender;
1672
- sqlite3_int64 id; /* New subscriber Id */
16731672
const char *zCode; /* New subscriber code (in hex) */
16741673
const char *zGoto = P("g");
16751674
int nsub = 0;
16761675
char ssub[20];
16771676
CapabilityString *pCap;
@@ -1683,34 +1682,31 @@
16831682
if( capability_has_any(pCap,"r") ) ssub[nsub++] = 't';
16841683
if( capability_has_any(pCap,"j") ) ssub[nsub++] = 'w';
16851684
ssub[nsub] = 0;
16861685
capability_free(pCap);
16871686
/* Also add the user to the subscriber table. */
1688
- db_multi_exec(
1687
+ zCode = db_text(0,
16891688
"INSERT INTO subscriber(semail,suname,"
16901689
" sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
16911690
" VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
16921691
" ON CONFLICT(semail) DO UPDATE"
1693
- " SET suname=excluded.suname",
1692
+ " SET suname=excluded.suname"
1693
+ " RETURNING hex(subscriberCode);",
16941694
/* semail */ zEAddr,
16951695
/* suname */ zUserID,
16961696
/* sverified */ 0,
16971697
/* sdigest */ 0,
16981698
/* ssub */ ssub,
16991699
/* smip */ g.zIpAddr
17001700
);
1701
- id = db_last_insert_rowid();
17021701
if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q"
17031702
" AND sverified", zEAddr) ){
17041703
/* This the case where the user was formerly a verified subscriber
17051704
** and here they have also registered as a user as well. It is
17061705
** not necessary to repeat the verfication step */
17071706
redirect_to_g();
17081707
}
1709
- zCode = db_text(0,
1710
- "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1711
- id);
17121708
/* A verification email */
17131709
pSender = alert_sender_new(0,0);
17141710
blob_init(&hdr,0,0);
17151711
blob_init(&body,0,0);
17161712
blob_appendf(&hdr, "To: <%s>\n", zEAddr);
17171713
--- src/login.c
+++ src/login.c
@@ -1667,11 +1667,10 @@
1667 login_set_user_cookie(zUserID, uid, NULL, 0);
1668 if( doAlerts ){
1669 /* Also make the new user a subscriber. */
1670 Blob hdr, body;
1671 AlertSender *pSender;
1672 sqlite3_int64 id; /* New subscriber Id */
1673 const char *zCode; /* New subscriber code (in hex) */
1674 const char *zGoto = P("g");
1675 int nsub = 0;
1676 char ssub[20];
1677 CapabilityString *pCap;
@@ -1683,34 +1682,31 @@
1683 if( capability_has_any(pCap,"r") ) ssub[nsub++] = 't';
1684 if( capability_has_any(pCap,"j") ) ssub[nsub++] = 'w';
1685 ssub[nsub] = 0;
1686 capability_free(pCap);
1687 /* Also add the user to the subscriber table. */
1688 db_multi_exec(
1689 "INSERT INTO subscriber(semail,suname,"
1690 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1691 " VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1692 " ON CONFLICT(semail) DO UPDATE"
1693 " SET suname=excluded.suname",
 
1694 /* semail */ zEAddr,
1695 /* suname */ zUserID,
1696 /* sverified */ 0,
1697 /* sdigest */ 0,
1698 /* ssub */ ssub,
1699 /* smip */ g.zIpAddr
1700 );
1701 id = db_last_insert_rowid();
1702 if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q"
1703 " AND sverified", zEAddr) ){
1704 /* This the case where the user was formerly a verified subscriber
1705 ** and here they have also registered as a user as well. It is
1706 ** not necessary to repeat the verfication step */
1707 redirect_to_g();
1708 }
1709 zCode = db_text(0,
1710 "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1711 id);
1712 /* A verification email */
1713 pSender = alert_sender_new(0,0);
1714 blob_init(&hdr,0,0);
1715 blob_init(&body,0,0);
1716 blob_appendf(&hdr, "To: <%s>\n", zEAddr);
1717
--- src/login.c
+++ src/login.c
@@ -1667,11 +1667,10 @@
1667 login_set_user_cookie(zUserID, uid, NULL, 0);
1668 if( doAlerts ){
1669 /* Also make the new user a subscriber. */
1670 Blob hdr, body;
1671 AlertSender *pSender;
 
1672 const char *zCode; /* New subscriber code (in hex) */
1673 const char *zGoto = P("g");
1674 int nsub = 0;
1675 char ssub[20];
1676 CapabilityString *pCap;
@@ -1683,34 +1682,31 @@
1682 if( capability_has_any(pCap,"r") ) ssub[nsub++] = 't';
1683 if( capability_has_any(pCap,"j") ) ssub[nsub++] = 'w';
1684 ssub[nsub] = 0;
1685 capability_free(pCap);
1686 /* Also add the user to the subscriber table. */
1687 zCode = db_text(0,
1688 "INSERT INTO subscriber(semail,suname,"
1689 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1690 " VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1691 " ON CONFLICT(semail) DO UPDATE"
1692 " SET suname=excluded.suname"
1693 " RETURNING hex(subscriberCode);",
1694 /* semail */ zEAddr,
1695 /* suname */ zUserID,
1696 /* sverified */ 0,
1697 /* sdigest */ 0,
1698 /* ssub */ ssub,
1699 /* smip */ g.zIpAddr
1700 );
 
1701 if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q"
1702 " AND sverified", zEAddr) ){
1703 /* This the case where the user was formerly a verified subscriber
1704 ** and here they have also registered as a user as well. It is
1705 ** not necessary to repeat the verfication step */
1706 redirect_to_g();
1707 }
 
 
 
1708 /* A verification email */
1709 pSender = alert_sender_new(0,0);
1710 blob_init(&hdr,0,0);
1711 blob_init(&body,0,0);
1712 blob_appendf(&hdr, "To: <%s>\n", zEAddr);
1713
+2 -2
--- src/main.c
+++ src/main.c
@@ -677,12 +677,12 @@
677677
}
678678
#endif
679679
680680
fossil_printf_selfcheck();
681681
fossil_limit_memory(1);
682
- if( sqlite3_libversion_number()<3034000 ){
683
- fossil_panic("Unsuitable SQLite version %s, must be at least 3.34.0",
682
+ if( sqlite3_libversion_number()<3035000 ){
683
+ fossil_panic("Unsuitable SQLite version %s, must be at least 3.35.0",
684684
sqlite3_libversion());
685685
}
686686
sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
687687
sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
688688
memset(&g, 0, sizeof(g));
689689
--- src/main.c
+++ src/main.c
@@ -677,12 +677,12 @@
677 }
678 #endif
679
680 fossil_printf_selfcheck();
681 fossil_limit_memory(1);
682 if( sqlite3_libversion_number()<3034000 ){
683 fossil_panic("Unsuitable SQLite version %s, must be at least 3.34.0",
684 sqlite3_libversion());
685 }
686 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
687 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
688 memset(&g, 0, sizeof(g));
689
--- src/main.c
+++ src/main.c
@@ -677,12 +677,12 @@
677 }
678 #endif
679
680 fossil_printf_selfcheck();
681 fossil_limit_memory(1);
682 if( sqlite3_libversion_number()<3035000 ){
683 fossil_panic("Unsuitable SQLite version %s, must be at least 3.35.0",
684 sqlite3_libversion());
685 }
686 sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
687 sqlite3_config(SQLITE_CONFIG_LOG, fossil_sqlite_log, 0);
688 memset(&g, 0, sizeof(g));
689
+3 -4
--- src/manifest.c
+++ src/manifest.c
@@ -2325,11 +2325,11 @@
23252325
if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
23262326
char *zCom;
23272327
parentid = manifest_add_checkin_linkages(rid,p,p->nParent,p->azParent);
23282328
search_doc_touch('c', rid, 0);
23292329
assert( manifest_event_triggers_are_enabled );
2330
- db_multi_exec(
2330
+ zCom = db_text(0,
23312331
"REPLACE INTO event(type,mtime,objid,user,comment,"
23322332
"bgcolor,euser,ecomment,omtime)"
23332333
"VALUES('ci',"
23342334
" coalesce("
23352335
" (SELECT julianday(value) FROM tagxref WHERE tagid=%d AND rid=%d),"
@@ -2336,19 +2336,18 @@
23362336
" %.17g"
23372337
" ),"
23382338
" %d,%Q,%Q,"
23392339
" (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d AND tagtype>0),"
23402340
" (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),"
2341
- " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),%.17g);",
2341
+ " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),%.17g)"
2342
+ "RETURNING coalesce(ecomment,comment);",
23422343
TAG_DATE, rid, p->rDate,
23432344
rid, p->zUser, p->zComment,
23442345
TAG_BGCOLOR, rid,
23452346
TAG_USER, rid,
23462347
TAG_COMMENT, rid, p->rDate
23472348
);
2348
- zCom = db_text(0, "SELECT coalesce(ecomment, comment) FROM event"
2349
- " WHERE rowid=last_insert_rowid()");
23502349
backlink_extract(zCom, 0, rid, BKLNK_COMMENT, p->rDate, 1);
23512350
fossil_free(zCom);
23522351
23532352
/* If this is a delta-manifest, record the fact that this repository
23542353
** contains delta manifests, to free the "commit" logic to generate
23552354
--- src/manifest.c
+++ src/manifest.c
@@ -2325,11 +2325,11 @@
2325 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
2326 char *zCom;
2327 parentid = manifest_add_checkin_linkages(rid,p,p->nParent,p->azParent);
2328 search_doc_touch('c', rid, 0);
2329 assert( manifest_event_triggers_are_enabled );
2330 db_multi_exec(
2331 "REPLACE INTO event(type,mtime,objid,user,comment,"
2332 "bgcolor,euser,ecomment,omtime)"
2333 "VALUES('ci',"
2334 " coalesce("
2335 " (SELECT julianday(value) FROM tagxref WHERE tagid=%d AND rid=%d),"
@@ -2336,19 +2336,18 @@
2336 " %.17g"
2337 " ),"
2338 " %d,%Q,%Q,"
2339 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d AND tagtype>0),"
2340 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),"
2341 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),%.17g);",
 
2342 TAG_DATE, rid, p->rDate,
2343 rid, p->zUser, p->zComment,
2344 TAG_BGCOLOR, rid,
2345 TAG_USER, rid,
2346 TAG_COMMENT, rid, p->rDate
2347 );
2348 zCom = db_text(0, "SELECT coalesce(ecomment, comment) FROM event"
2349 " WHERE rowid=last_insert_rowid()");
2350 backlink_extract(zCom, 0, rid, BKLNK_COMMENT, p->rDate, 1);
2351 fossil_free(zCom);
2352
2353 /* If this is a delta-manifest, record the fact that this repository
2354 ** contains delta manifests, to free the "commit" logic to generate
2355
--- src/manifest.c
+++ src/manifest.c
@@ -2325,11 +2325,11 @@
2325 if( !db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){
2326 char *zCom;
2327 parentid = manifest_add_checkin_linkages(rid,p,p->nParent,p->azParent);
2328 search_doc_touch('c', rid, 0);
2329 assert( manifest_event_triggers_are_enabled );
2330 zCom = db_text(0,
2331 "REPLACE INTO event(type,mtime,objid,user,comment,"
2332 "bgcolor,euser,ecomment,omtime)"
2333 "VALUES('ci',"
2334 " coalesce("
2335 " (SELECT julianday(value) FROM tagxref WHERE tagid=%d AND rid=%d),"
@@ -2336,19 +2336,18 @@
2336 " %.17g"
2337 " ),"
2338 " %d,%Q,%Q,"
2339 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d AND tagtype>0),"
2340 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),"
2341 " (SELECT value FROM tagxref WHERE tagid=%d AND rid=%d),%.17g)"
2342 "RETURNING coalesce(ecomment,comment);",
2343 TAG_DATE, rid, p->rDate,
2344 rid, p->zUser, p->zComment,
2345 TAG_BGCOLOR, rid,
2346 TAG_USER, rid,
2347 TAG_COMMENT, rid, p->rDate
2348 );
 
 
2349 backlink_extract(zCom, 0, rid, BKLNK_COMMENT, p->rDate, 1);
2350 fossil_free(zCom);
2351
2352 /* If this is a delta-manifest, record the fact that this repository
2353 ** contains delta manifests, to free the "commit" logic to generate
2354

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button