]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Always disallow functions as the DEFAULT of a column. Add assert()s and stat4-function
authordrh <drh@noemail.net>
Thu, 12 Mar 2015 21:02:36 +0000 (21:02 +0000)
committerdrh <drh@noemail.net>
Thu, 12 Mar 2015 21:02:36 +0000 (21:02 +0000)
FossilOrigin-Name: a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3

manifest
manifest.uuid
src/alter.c
src/vdbeapi.c
src/vdbemem.c

index 9c102ed96c85cef9e65bdd6c700bafa138335eab..06dd27ad1c65361ee4c4ef905452bb7d8609a20d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C If\san\serror\soccurs\sin\sthe\scompile-time\sevaluation\sof\san\sapplication-defined\nfunction,\sthen\spropagate\sback\sout\sthe\sexact\serror\scode,\snot\sjust\sthe\ngeneric\sSQLITE_ERROR.
-D 2015-03-12T18:38:51.338
+C Always\sdisallow\sfunctions\sas\sthe\sDEFAULT\sof\sa\scolumn.\s\sAdd\sassert()s\sand
+D 2015-03-12T21:02:36.947
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
 F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
-F src/alter.c 809313ddb2dea2a8cdd2d0da944d6a859e3657dc
+F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81
 F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d
 F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8
 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
@@ -296,10 +296,10 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec
 F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34
 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3
 F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a
-F src/vdbeapi.c da6551c9a9b9272f9cf7c776a09302ce9ca691d3
+F src/vdbeapi.c 1295402cabda4473ddee24955c8f7039514497e4
 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5
 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
-F src/vdbemem.c 981fa5ac239d6a646b5720779844d991277dcd07
+F src/vdbemem.c d52fa9f3bcf75d27d7b7846d81ee7898829c763d
 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2
 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010
 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01
@@ -1242,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 8fb6bd9be59d6b04e922d7b246aaefd4851539b6
-R 46972b8481418c9af660c8cf08bd0f3b
+P 93f42586cc9db63c5a4599ce06630e60204a5bc9
+R b3d39823270cf35170812e8663c1c07d
 U drh
-Z f07316ba19973dffcb9b3c2ed85bb043
+Z b97bd037eac2f46713c8bf83215d5d81
index b430dfd5466f14524cf571d30f063ea515c66ea4..22a8fe8715d832129d7baf4a6f39bc2799c017c0 100644 (file)
@@ -1 +1 @@
-93f42586cc9db63c5a4599ce06630e60204a5bc9
\ No newline at end of file
+a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3
\ No newline at end of file
index 908b251f06d9c585e936807b49fc738f26bce35d..03605b25aa50e783edd76daf3ec06cbef82b553d 100644 (file)
@@ -690,9 +690,10 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
   */
   if( pDflt ){
     sqlite3_value *pVal = 0;
-    if( pDflt->op!=TK_FUNCTION
-     && sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) 
-    ){
+    int rc;
+    rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal);
+    assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
+    if( rc!=SQLITE_OK ){
       db->mallocFailed = 1;
       return;
     }
index 42cc715d7ce3c517f633ac74f022e279df823f30..ae53d9300690cd94b9df0182e08db22823d5e228 100644 (file)
@@ -370,7 +370,7 @@ void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
   pCtx->isError = errCode;
   pCtx->fErrorOrAux = 1;
 #ifdef SQLITE_DEBUG
-  pCtx->pVdbe->rcApp = errCode;
+  if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
 #endif
   if( pCtx->pOut->flags & MEM_Null ){
     sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, 
index 353bfa7255ed30c9d7d6d7dc9b264c050328d9a4..0e9bb873aec36dca0ae35f9044f79a5d8f91fe95 100644 (file)
@@ -1090,7 +1090,7 @@ struct ValueNewStat4Ctx {
 ** Otherwise, if the second argument is non-zero, then this function is 
 ** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
 ** already been allocated, allocate the UnpackedRecord structure that 
-** that function will return to its caller here. Then return a pointer 
+** that function will return to its caller here. Then return a pointer to
 ** an sqlite3_value within the UnpackedRecord.a[] array.
 */
 static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
@@ -1173,10 +1173,10 @@ static int valueFromFunction(
   ExprList *pList = 0;            /* Function arguments */
   int i;                          /* Iterator variable */
 
-  if( (p->flags & EP_TokenOnly)==0 ){
-    pList = p->x.pList;
-    if( pList ) nVal = pList->nExpr;
-  }
+  assert( pCtx!=0 );
+  assert( (p->flags & EP_TokenOnly)==0 );
+  pList = p->x.pList;
+  if( pList ) nVal = pList->nExpr;
   nName = sqlite3Strlen30(p->u.zToken);
   pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
   assert( pFunc );
@@ -1210,15 +1210,12 @@ static int valueFromFunction(
   pFunc->xFunc(&ctx, nVal, apVal);
   if( ctx.isError ){
     rc = ctx.isError;
-    if( pCtx ){
-      sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
-      pCtx->pParse->rc = rc;
-    }
+    sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
+    pCtx->pParse->rc = rc;
   }else{
     sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
-    if( rc==SQLITE_OK ){
-      rc = sqlite3VdbeChangeEncoding(pVal, enc);
-    }
+    assert( rc==SQLITE_OK );
+    rc = sqlite3VdbeChangeEncoding(pVal, enc);
     if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){
       rc = SQLITE_TOOBIG;
     }
@@ -1226,7 +1223,6 @@ static int valueFromFunction(
 
  value_from_function_out:
   if( rc!=SQLITE_OK ){
-    if( pCtx==0 ) sqlite3ValueFree(pVal);
     pVal = 0;
   }
   if( apVal ){
@@ -1275,6 +1271,12 @@ static int valueFromExpr(
   while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft;
   if( NEVER(op==TK_REGISTER) ) op = pExpr->op2;
 
+  /* Compressed expressions only appear when parsing the DEFAULT clause
+  ** on a table column definition, and hence only when pCtx==0.  This
+  ** check ensures that an EP_TokenOnly expression is never passed down
+  ** into valueFromFunction(). */
+  assert( (pExpr->flags & EP_TokenOnly)==0 || pCtx==0 );
+
   if( op==TK_CAST ){
     u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
     rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
@@ -1351,7 +1353,7 @@ static int valueFromExpr(
   }
 #endif
 
-  else if( op==TK_FUNCTION ){
+  else if( op==TK_FUNCTION && pCtx!=0 ){
     rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
   }