From: drh Date: Wed, 12 Dec 2007 12:00:45 +0000 (+0000) Subject: Add a new OP_StackDepth opcode to help detect VDBE stack leaks early, X-Git-Tag: version-3.6.10~1565 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a99e8811760cb6a6a4716c6650ef0921afcf9e95;p=thirdparty%2Fsqlite.git Add a new OP_StackDepth opcode to help detect VDBE stack leaks early, before they cause damage. For diagnostics in ticket #2832. (CVS 4612) FossilOrigin-Name: 3fd6a267533cedcca9b8ba3533c107d7341a06c6 --- diff --git a/manifest b/manifest index c607c9d4cc..bc900051b6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stest\snumbering\sin\stkt2822.test.\sTicket\s#2830.\s(CVS\s4611) -D 2007-12-12T04:38:27 +C Add\sa\snew\sOP_StackDepth\sopcode\sto\shelp\sdetect\sVDBE\sstack\sleaks\searly,\r\nbefore\sthey\scause\sdamage.\s\sFor\sdiagnostics\sin\sticket\s#2832.\s(CVS\s4612) +D 2007-12-12T12:00:46 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.in 0590398f62fc2c456ff4c45e9741f5a718b7e2ac F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -164,11 +164,11 @@ F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59 F src/test_thread.c a98d69cae883e53d3686fc25889a5fa5f51439f8 F src/tokenize.c 67e42600ab34f976f2b1288c499ad6c98d652f0e F src/trigger.c 66695e1375b969ea41a38dec9f40ea28bb0ac767 -F src/update.c 2add92a6159fa73128653706574afbcd8fd1dd80 +F src/update.c 3725377d6226f6a1f15885e112435df3a5e4770d F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736 F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624 F src/vacuum.c 25ffbd766f25bca099ead1c1e11f5528c86102b8 -F src/vdbe.c a99beac1162fa490c4b75ac36ed97146ab181837 +F src/vdbe.c 24376fd0c28a52ebb410292a2261e5174d862cc0 F src/vdbe.h 79e09ff13b85457abe437d9814454534ebbc1fe3 F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247 F src/vdbeapi.c dd2c43317294e0a013e9f634ee4209a3ea459b43 @@ -598,7 +598,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 9335c940504f5979066b70ec445b57acfb251713 -R d03a5445f8be128fa7f48f15551925f2 -U danielk1977 -Z bf201abd015205614969c923308ec87e +P 8fe8e9c460e0f8ebc4267de96b0c971cb6370861 +R 6bd8f89e70a38f2a5c36552ce2b40f8f +U drh +Z 14e8caa139e0c85a2dd57b679935e880 diff --git a/manifest.uuid b/manifest.uuid index 2bc83fdbd0..df8b417212 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8fe8e9c460e0f8ebc4267de96b0c971cb6370861 \ No newline at end of file +3fd6a267533cedcca9b8ba3533c107d7341a06c6 \ No newline at end of file diff --git a/src/update.c b/src/update.c index 319aa4f186..c053ac17cd 100644 --- a/src/update.c +++ b/src/update.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.141 2007/11/11 18:36:34 drh Exp $ +** $Id: update.c,v 1.142 2007/12/12 12:00:46 drh Exp $ */ #include "sqliteInt.h" @@ -330,6 +330,7 @@ void sqlite3Update( /* The top of the update loop for when there are triggers. */ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0); + sqlite3VdbeAddOp(v, OP_StackDepth, -1, 0); mem1 = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, mem1, 0); @@ -427,6 +428,7 @@ void sqlite3Update( */ if( !triggers_exist ){ addr = sqlite3VdbeAddOp(v, OP_FifoRead, 0, 0); + sqlite3VdbeAddOp(v, OP_StackDepth, -1, 0); sqlite3VdbeAddOp(v, OP_Dup, 0, 0); } sqlite3VdbeAddOp(v, OP_NotExists, iCur, addr); diff --git a/src/vdbe.c b/src/vdbe.c index 32ed09318f..fdeb4f26af 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.656 2007/12/04 16:54:53 drh Exp $ +** $Id: vdbe.c,v 1.657 2007/12/12 12:00:46 drh Exp $ */ #include "sqliteInt.h" #include @@ -692,6 +692,28 @@ case OP_Halt: { /* no-push */ goto vdbe_return; } +/* Opcode: StackDepth P1 * * +** +** If P1 is less than zero, then store the current stack depth +** in P1. If P1 is zero or greater, verify that the current stack +** depth is equal to P1 and throw an exception if it is not. +** +** This opcode is used for internal consistency checking. +*/ +case OP_StackDepth: { /* no-push */ + if( pOp->p1<0 ){ + pOp->p1 = pTos - p->aStack + 1; + }else if( pOp->p1!=pTos - p->aStack + 1 ){ + p->pTos = pTos; + p->rc = SQLITE_ERROR; + p->pc = pc; + p->errorAction = OE_Rollback; + sqlite3SetString(&p->zErrMsg, "internal VDBE stack overflow", (char*)0); + goto vdbe_return; + } + break; +} + /* Opcode: Integer P1 * * ** ** The 32-bit integer value P1 is pushed onto the stack.