/ Check-in [b74cb0a9]
Login

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

Overview
Comment:If a virtual table is created with a malformed UTF8 name in a UTF16 database, make sure that does not cause problems.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b74cb0a92bba69f8ea705adf4695d03ea4470984
User & Date: drh 2015-03-19 20:09:16
Context
2015-03-20
08:43
Fix a problem causing collation sequence names to be dequoted multiple times under some circumstances. check-in: eddc05e7 user: dan tags: trunk
2015-03-19
20:09
If a virtual table is created with a malformed UTF8 name in a UTF16 database, make sure that does not cause problems. check-in: b74cb0a9 user: drh tags: trunk
19:59
Fix a crash that can occur following an OOM condition within a CREATE VIRTUAL TABLE statement on a utf-16 database. Closed-Leaf check-in: 9453e7da user: dan tags: malformed-vtab-name
16:25
Fix an FTS3/4 problem with handling empty tokenizer declarations (e.g. "CREATE VIRTUAL TABLE t(tokenize=);"). check-in: 26d2def8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  6005   6005     rc = sqlite3VtabBegin(db, pVTab);
  6006   6006     if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab);
  6007   6007     break;
  6008   6008   }
  6009   6009   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  6010   6010   
  6011   6011   #ifndef SQLITE_OMIT_VIRTUALTABLE
  6012         -/* Opcode: VCreate P1 * * P4 *
         6012  +/* Opcode: VCreate P1 P2 * * *
  6013   6013   **
  6014         -** P4 is the name of a virtual table in database P1. Call the xCreate method
  6015         -** for that table.
         6014  +** P2 is a register that holds the name of a virtual table in database 
         6015  +** P1. Call the xCreate method for that table.
  6016   6016   */
  6017   6017   case OP_VCreate: {
  6018         -  rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg);
         6018  +  Mem sMem;          /* For storing the record being decoded */
         6019  +  memset(&sMem, 0, sizeof(sMem));
         6020  +  sMem.db = db;
         6021  +  rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]);
         6022  +  if( rc==SQLITE_OK ){
         6023  +    const char *zTab = (const char*)sqlite3_value_text(&sMem);
         6024  +    assert( zTab || db->mallocFailed );
         6025  +    if( zTab ){
         6026  +      rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg);
         6027  +    }
         6028  +  }
         6029  +  sqlite3VdbeMemRelease(&sMem);
  6019   6030     break;
  6020   6031   }
  6021   6032   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  6022   6033   
  6023   6034   #ifndef SQLITE_OMIT_VIRTUALTABLE
  6024   6035   /* Opcode: VDestroy P1 * * P4 *
  6025   6036   **

Changes to src/vtab.c.

   385    385     ** do additional initialization work and store the statement text
   386    386     ** in the sqlite_master table.
   387    387     */
   388    388     if( !db->init.busy ){
   389    389       char *zStmt;
   390    390       char *zWhere;
   391    391       int iDb;
          392  +    int iReg;
   392    393       Vdbe *v;
   393    394   
   394    395       /* Compute the complete text of the CREATE VIRTUAL TABLE statement */
   395    396       if( pEnd ){
   396    397         pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
   397    398       }
   398    399       zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
................................................................................
   419    420       sqlite3DbFree(db, zStmt);
   420    421       v = sqlite3GetVdbe(pParse);
   421    422       sqlite3ChangeCookie(pParse, iDb);
   422    423   
   423    424       sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
   424    425       zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
   425    426       sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
   426         -    sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0, 
   427         -                         pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
          427  +
          428  +    iReg = ++pParse->nMem;
          429  +    sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0);
          430  +    sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
   428    431     }
   429    432   
   430    433     /* If we are rereading the sqlite_master table create the in-memory
   431    434     ** record of the table. The xConnect() method is not called until
   432    435     ** the first time the virtual table is used in an SQL statement. This
   433    436     ** allows a schema that contains virtual tables to be loaded before
   434    437     ** the required virtual table implementations are registered.  */

Changes to test/vtab2.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13         -# $Id: vtab2.test,v 1.9 2008/10/13 10:37:50 danielk1977 Exp $
    14     13   
    15     14   set testdir [file dirname $argv0]
    16     15   source $testdir/tester.tcl
           16  +set testprefix vtab2
    17     17   
    18     18   ifcapable !vtab||!schema_pragmas {
    19     19     finish_test
    20     20     return
    21     21   }
    22     22   
    23     23   register_schema_module [sqlite3_connection_pointer db]
................................................................................
   128    128       UPDATE fkey 
   129    129       SET to_col = (SELECT name FROM v_col WHERE tablename = 't1' AND pk);
   130    130     }
   131    131   } {}
   132    132   do_test vtab2-4.5 {
   133    133     execsql { SELECT * FROM fkey }
   134    134   } {t1 a}
          135  +
          136  +#-------------------------------------------------------------------------
          137  +#
          138  +reset_db
          139  +do_execsql_test 5.1 {
          140  +  PRAGMA encoding='UTF16';
          141  +}
          142  +
          143  +do_test 5.2 {
          144  +  sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 }
          145  +} {0 {}}
          146  +
          147  +do_test 5.3 {
          148  +  sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s }
          149  +} {/1 {malformed database schema.* already exists}/}
          150  +
          151  +
   135    152   
   136    153   finish_test
          154  +