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

Always disallow functions as the DEFAULT of a column. Add assert()s and

FossilOrigin-Name: a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3
This commit is contained in:
drh
2015-03-12 21:02:36 +00:00
parent 81367381a9
commit 96f4ad20fd
5 changed files with 30 additions and 27 deletions

View File

@@ -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. C Always\sdisallow\sfunctions\sas\sthe\sDEFAULT\sof\sa\scolumn.\s\sAdd\sassert()s\sand
D 2015-03-12T18:38:51.338 D 2015-03-12T21:02:36.947
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb F Makefile.in 88a3e6261286db378fdffa1124cad11b3c05f5bb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,7 +166,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786 F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c 809313ddb2dea2a8cdd2d0da944d6a859e3657dc F src/alter.c d23d6b6991f66b383934f137fd4384d93fb98c81
F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d F src/analyze.c 91540f835163d5369ccbae78e2e6c74d0dd53c1d
F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8 F src/attach.c 880f9b8641a829c563e52dd13c452ce457ae4dd8
F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
@@ -296,10 +296,10 @@ F src/vacuum.c 9460b9de7b2d4e34b0d374894aa6c8a0632be8ec
F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34 F src/vdbe.c 94cbc2115075b1a562a2a702c29ba48e74f85d34
F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3 F src/vdbe.h 6fc69d9c5e146302c56e163cb4b31d1ee64a18c3
F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a F src/vdbeInt.h bb56fd199d8af1a2c1b9639ee2f70724b4338e3a
F src/vdbeapi.c da6551c9a9b9272f9cf7c776a09302ce9ca691d3 F src/vdbeapi.c 1295402cabda4473ddee24955c8f7039514497e4
F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5 F src/vdbeaux.c 97911edb61074b871ec4aa2d6bb779071643dee5
F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
F src/vdbemem.c 981fa5ac239d6a646b5720779844d991277dcd07 F src/vdbemem.c d52fa9f3bcf75d27d7b7846d81ee7898829c763d
F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2 F src/vdbesort.c 6d64c5448b64851b99931ede980addc3af70d5e2
F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010 F src/vdbetrace.c 7e4222955e07dd707a2f360c0eb73452be1cb010
F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01
@@ -1242,7 +1242,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 8fb6bd9be59d6b04e922d7b246aaefd4851539b6 P 93f42586cc9db63c5a4599ce06630e60204a5bc9
R 46972b8481418c9af660c8cf08bd0f3b R b3d39823270cf35170812e8663c1c07d
U drh U drh
Z f07316ba19973dffcb9b3c2ed85bb043 Z b97bd037eac2f46713c8bf83215d5d81

View File

@@ -1 +1 @@
93f42586cc9db63c5a4599ce06630e60204a5bc9 a991bb1a9eb54bdbd45bd623e8b304bdfeb481a3

View File

@@ -690,9 +690,10 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
*/ */
if( pDflt ){ if( pDflt ){
sqlite3_value *pVal = 0; sqlite3_value *pVal = 0;
if( pDflt->op!=TK_FUNCTION int rc;
&& sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal);
){ assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
if( rc!=SQLITE_OK ){
db->mallocFailed = 1; db->mallocFailed = 1;
return; return;
} }

View File

@@ -370,7 +370,7 @@ void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
pCtx->isError = errCode; pCtx->isError = errCode;
pCtx->fErrorOrAux = 1; pCtx->fErrorOrAux = 1;
#ifdef SQLITE_DEBUG #ifdef SQLITE_DEBUG
pCtx->pVdbe->rcApp = errCode; if( pCtx->pVdbe ) pCtx->pVdbe->rcApp = errCode;
#endif #endif
if( pCtx->pOut->flags & MEM_Null ){ if( pCtx->pOut->flags & MEM_Null ){
sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1, sqlite3VdbeMemSetStr(pCtx->pOut, sqlite3ErrStr(errCode), -1,

View File

@@ -1090,7 +1090,7 @@ struct ValueNewStat4Ctx {
** Otherwise, if the second argument is non-zero, then this function is ** Otherwise, if the second argument is non-zero, then this function is
** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not ** being called indirectly by sqlite3Stat4ProbeSetValue(). If it has not
** already been allocated, allocate the UnpackedRecord structure that ** 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. ** an sqlite3_value within the UnpackedRecord.a[] array.
*/ */
static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
@@ -1173,10 +1173,10 @@ static int valueFromFunction(
ExprList *pList = 0; /* Function arguments */ ExprList *pList = 0; /* Function arguments */
int i; /* Iterator variable */ int i; /* Iterator variable */
if( (p->flags & EP_TokenOnly)==0 ){ assert( pCtx!=0 );
pList = p->x.pList; assert( (p->flags & EP_TokenOnly)==0 );
if( pList ) nVal = pList->nExpr; pList = p->x.pList;
} if( pList ) nVal = pList->nExpr;
nName = sqlite3Strlen30(p->u.zToken); nName = sqlite3Strlen30(p->u.zToken);
pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0); pFunc = sqlite3FindFunction(db, p->u.zToken, nName, nVal, enc, 0);
assert( pFunc ); assert( pFunc );
@@ -1210,15 +1210,12 @@ static int valueFromFunction(
pFunc->xFunc(&ctx, nVal, apVal); pFunc->xFunc(&ctx, nVal, apVal);
if( ctx.isError ){ if( ctx.isError ){
rc = ctx.isError; rc = ctx.isError;
if( pCtx ){ sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal));
sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); pCtx->pParse->rc = rc;
pCtx->pParse->rc = rc;
}
}else{ }else{
sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
if( rc==SQLITE_OK ){ assert( rc==SQLITE_OK );
rc = sqlite3VdbeChangeEncoding(pVal, enc); rc = sqlite3VdbeChangeEncoding(pVal, enc);
}
if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){
rc = SQLITE_TOOBIG; rc = SQLITE_TOOBIG;
} }
@@ -1226,7 +1223,6 @@ static int valueFromFunction(
value_from_function_out: value_from_function_out:
if( rc!=SQLITE_OK ){ if( rc!=SQLITE_OK ){
if( pCtx==0 ) sqlite3ValueFree(pVal);
pVal = 0; pVal = 0;
} }
if( apVal ){ if( apVal ){
@@ -1275,6 +1271,12 @@ static int valueFromExpr(
while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft; while( (op = pExpr->op)==TK_UPLUS ) pExpr = pExpr->pLeft;
if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; 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 ){ if( op==TK_CAST ){
u8 aff = sqlite3AffinityType(pExpr->u.zToken,0); u8 aff = sqlite3AffinityType(pExpr->u.zToken,0);
rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx); rc = valueFromExpr(db, pExpr->pLeft, enc, aff, ppVal, pCtx);
@@ -1351,7 +1353,7 @@ static int valueFromExpr(
} }
#endif #endif
else if( op==TK_FUNCTION ){ else if( op==TK_FUNCTION && pCtx!=0 ){
rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx); rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
} }