/ Check-in [5a027fe4]
Login

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

Overview
Comment:Fix sqlite3VdbeExpandSql() so that it handles OOMs by always returning NULL.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sqlite3_trace_v2
Files: files | file ages | folders
SHA1: 5a027fe4127d498e0dc0d9439131c6a29085cf0a
User & Date: drh 2016-07-23 00:43:14
Context
2016-07-23
02:07
Add requirements marks to the sqlite3_trace_v2() interface documentation. check-in: ebd388e9 user: drh tags: sqlite3_trace_v2
00:43
Fix sqlite3VdbeExpandSql() so that it handles OOMs by always returning NULL. check-in: 5a027fe4 user: drh tags: sqlite3_trace_v2
2016-07-22
20:45
Be sure to hold the database connection mutex while calling sqlite3VdbeExpand() from within sqlite3_expanded_sql(). check-in: 527b5ba6 user: drh tags: sqlite3_trace_v2
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

    81     81   ** The SQLITE_TRACE_SIZE_LIMIT puts an upper bound on the size of
    82     82   ** expanded bound parameters.
    83     83   */
    84     84   char *sqlite3_expanded_sql(sqlite3_stmt *pStmt){
    85     85   #ifdef SQLITE_OMIT_TRACE
    86     86     return 0;
    87     87   #else
    88         -  Vdbe *p = (Vdbe *)pStmt;
    89         -  char *z;
    90         -  if( p==0 || p->zSql==0 ) return 0;
    91         -  sqlite3_mutex_enter(p->db->mutex);
    92         -  z = sqlite3VdbeExpandSql(p, p->zSql);
    93         -  sqlite3_mutex_leave(p->db->mutex);
           88  +  char *z = 0;
           89  +  const char *zSql = sqlite3_sql(pStmt);
           90  +  if( zSql ){
           91  +    Vdbe *p = (Vdbe *)pStmt;
           92  +    sqlite3_mutex_enter(p->db->mutex);
           93  +    z = sqlite3VdbeExpandSql(p, zSql);
           94  +    sqlite3_mutex_leave(p->db->mutex);
           95  +  }
    94     96     return z;
    95     97   #endif
    96     98   }
    97     99   
    98    100   /*
    99    101   ** Swap all content between two VDBE structures.
   100    102   */

Changes to src/vdbetrace.c.

    77     77     int idx = 0;             /* Index of a host parameter */
    78     78     int nextIndex = 1;       /* Index of next ? host parameter */
    79     79     int n;                   /* Length of a token prefix */
    80     80     int nToken;              /* Length of the parameter token */
    81     81     int i;                   /* Loop counter */
    82     82     Mem *pVar;               /* Value of a host parameter */
    83     83     StrAccum out;            /* Accumulate the output here */
           84  +#ifndef SQLITE_OMIT_UTF16
           85  +  Mem utf8;                /* Used to convert UTF16 parameters into UTF8 for display */
           86  +#endif
    84     87     char zBase[100];         /* Initial working space */
    85     88   
    86     89     db = p->db;
    87     90     sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase), 
    88     91                         db->aLimit[SQLITE_LIMIT_LENGTH]);
    89     92     if( db->nVdbeExec>1 ){
    90     93       while( *zRawSql ){
................................................................................
   131    134           sqlite3XPrintf(&out, "%lld", pVar->u.i);
   132    135         }else if( pVar->flags & MEM_Real ){
   133    136           sqlite3XPrintf(&out, "%!.15g", pVar->u.r);
   134    137         }else if( pVar->flags & MEM_Str ){
   135    138           int nOut;  /* Number of bytes of the string text to include in output */
   136    139   #ifndef SQLITE_OMIT_UTF16
   137    140           u8 enc = ENC(db);
   138         -        Mem utf8;
   139    141           if( enc!=SQLITE_UTF8 ){
   140    142             memset(&utf8, 0, sizeof(utf8));
   141    143             utf8.db = db;
   142         -          sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
   143         -          sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8);
          144  +          if( SQLITE_NOMEM== sqlite3VdbeMemSetStr(&utf8,pVar->z,pVar->n,enc,SQLITE_STATIC)
          145  +           || SQLITE_NOMEM== sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8)
          146  +          ){
          147  +            sqlite3StrAccumReset(&out);
          148  +            sqlite3VdbeMemRelease(&utf8);
          149  +            return 0;
          150  +          }
   144    151             pVar = &utf8;
   145    152           }
   146    153   #endif
   147    154           nOut = pVar->n;
   148    155   #ifdef SQLITE_TRACE_SIZE_LIMIT
   149    156           if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
   150    157             nOut = SQLITE_TRACE_SIZE_LIMIT;