/ Check-in [a874c649]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the exprNodeCopy() routine that will safely memcpy() an Expr node that might be a size-reduced node.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a874c649960ba2e2b2fd380d08c02a45884a1060d3922be8847729008ca6766e
User & Date: drh 2019-01-05 21:56:12
Context
2019-05-07
02:57
Add the exprNodeCopy() routine that will safely memcpy() an Expr node that might be a size-reduced node. Leaf check-in: ab2ba8e7 user: drh tags: expr-node-copy-patch
2019-01-06
02:06
The page size becomes fixed as soon as page1 from a non-empty database file is read. check-in: 6064584d user: drh tags: trunk
01:46
Give symbolic names to the special prepared statements used to implement incremental blob I/O. Leaf check-in: 2a1cc632 user: drh tags: named-blob-I/O
2019-01-05
21:56
Add the exprNodeCopy() routine that will safely memcpy() an Expr node that might be a size-reduced node. check-in: a874c649 user: drh tags: trunk
21:09
If the OP_ParseSchema opcode with a non-NULL P4 operand does not parse any rows out of the sqlite_master table, that indicates that the sqlite_master table is corrupt, so raise an SQLITE_CORRUPT error. check-in: 598d7358 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1094   1094   ** EXPR_REDUCEDSIZE or EXPR_TOKENONLYSIZE.
  1095   1095   */
  1096   1096   static int exprStructSize(Expr *p){
  1097   1097     if( ExprHasProperty(p, EP_TokenOnly) ) return EXPR_TOKENONLYSIZE;
  1098   1098     if( ExprHasProperty(p, EP_Reduced) ) return EXPR_REDUCEDSIZE;
  1099   1099     return EXPR_FULLSIZE;
  1100   1100   }
         1101  +
         1102  +/*
         1103  +** Copy the complete content of an Expr node, taking care not to read
         1104  +** past the end of the structure for a reduced-size version of the source
         1105  +** Expr.
         1106  +*/
         1107  +static void exprNodeCopy(Expr *pDest, Expr *pSrc){
         1108  +  memset(pDest, 0, sizeof(Expr));
         1109  +  memcpy(pDest, pSrc, exprStructSize(pSrc));
         1110  +}
  1101   1111   
  1102   1112   /*
  1103   1113   ** The dupedExpr*Size() routines each return the number of bytes required
  1104   1114   ** to store a copy of an expression or expression tree.  They differ in
  1105   1115   ** how much of the tree is measured.
  1106   1116   **
  1107   1117   **     dupedExprStructSize()     Size of only the Expr structure 
................................................................................
  4047   4057         assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
  4048   4058         assert(pExpr->x.pList->nExpr > 0);
  4049   4059         pEList = pExpr->x.pList;
  4050   4060         aListelem = pEList->a;
  4051   4061         nExpr = pEList->nExpr;
  4052   4062         endLabel = sqlite3VdbeMakeLabel(pParse);
  4053   4063         if( (pX = pExpr->pLeft)!=0 ){
  4054         -        tempX = *pX;
         4064  +        exprNodeCopy(&tempX, pX);
  4055   4065           testcase( pX->op==TK_COLUMN );
  4056   4066           exprToRegister(&tempX, exprCodeVector(pParse, &tempX, &regFree1));
  4057   4067           testcase( regFree1==0 );
  4058   4068           memset(&opCompare, 0, sizeof(opCompare));
  4059   4069           opCompare.op = TK_EQ;
  4060   4070           opCompare.pLeft = &tempX;
  4061   4071           pTest = &opCompare;
................................................................................
  4368   4378   ){
  4369   4379    Expr exprAnd;     /* The AND operator in  x>=y AND x<=z  */
  4370   4380     Expr compLeft;    /* The  x>=y  term */
  4371   4381     Expr compRight;   /* The  x<=z  term */
  4372   4382     Expr exprX;       /* The  x  subexpression */
  4373   4383     int regFree1 = 0; /* Temporary use register */
  4374   4384   
  4375         -
  4376   4385     memset(&compLeft, 0, sizeof(Expr));
  4377   4386     memset(&compRight, 0, sizeof(Expr));
  4378   4387     memset(&exprAnd, 0, sizeof(Expr));
  4379   4388   
  4380   4389     assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
  4381         -  exprX = *pExpr->pLeft;
         4390  +  exprNodeCopy(&exprX, pExpr->pLeft);
  4382   4391     exprAnd.op = TK_AND;
  4383   4392     exprAnd.pLeft = &compLeft;
  4384   4393     exprAnd.pRight = &compRight;
  4385   4394     compLeft.op = TK_GE;
  4386   4395     compLeft.pLeft = &exprX;
  4387   4396     compLeft.pRight = pExpr->x.pList->a[0].pExpr;
  4388   4397     compRight.op = TK_LE;