/ Check-in [e736da9c]
Login

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

Overview
Comment:Have ".recover" handle cases where the sqlite_master table contains malformed SQL statements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e736da9c18fad138c5502d354c3553373cba15358b69e44b257f60def59422e2
User & Date: dan 2019-05-09 14:15:19
Context
2019-05-09
15:07
Fix further buffer overreads triggered by passing corrupt records to the sqlite_dbdata module. check-in: dbc6a9f7 user: dan tags: trunk
14:15
Have ".recover" handle cases where the sqlite_master table contains malformed SQL statements. check-in: e736da9c user: dan tags: trunk
11:45
Fix a problem with running the ".recover" command on a database that is zero pages in size. check-in: 47fa6534 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  6384   6384         shellFinalize(&rc, pPkFinder);
  6385   6385       }
  6386   6386     }
  6387   6387   
  6388   6388    finished:
  6389   6389     sqlite3_close(dbtmp);
  6390   6390     *pRc = rc;
  6391         -  if( rc!=SQLITE_OK ){
         6391  +  if( rc!=SQLITE_OK || (pTab && pTab->zQuoted==0) ){
  6392   6392       recoverFreeTable(pTab);
  6393   6393       pTab = 0;
  6394   6394     }
  6395   6395     return pTab;
  6396   6396   }
  6397   6397   
  6398   6398   /*
................................................................................
  6676   6676       }
  6677   6677       shellFinalize(&rc, pStmt);
  6678   6678     }
  6679   6679   
  6680   6680     /* Figure out if an orphan table will be required. And if so, how many
  6681   6681     ** user columns it should contain */
  6682   6682     shellPrepare(pState->db, &rc, 
  6683         -      "SELECT coalesce(max(maxlen), -2) FROM recovery.map" 
  6684         -      "  WHERE root>1 AND root NOT IN (SELECT rootpage FROM recovery.schema)"
         6683  +      "SELECT coalesce(max(maxlen), -2) FROM recovery.map WHERE root>1"
  6685   6684         , &pLoop
  6686   6685     );
  6687   6686     if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pLoop) ){
  6688   6687       nOrphan = sqlite3_column_int(pLoop, 0);
  6689   6688     }
  6690   6689     shellFinalize(&rc, pLoop);
  6691   6690     pLoop = 0;
  6692         -  pOrphan = recoverOrphanTable(pState, &rc, zLostAndFound, nOrphan);
  6693   6691   
  6694   6692     shellPrepare(pState->db, &rc,
  6695   6693         "SELECT pgno FROM recovery.map WHERE root=?", &pPages
  6696   6694     );
  6697   6695     shellPrepare(pState->db, &rc,
  6698   6696         "SELECT max(field), group_concat(shell_escape_crnl(quote(value)), ', ')"
  6699   6697         "FROM sqlite_dbdata WHERE pgno = ? AND field != ?"
................................................................................
  6712   6710       int bIntkey = sqlite3_column_int(pLoop, 1);
  6713   6711       int nCol = sqlite3_column_int(pLoop, 2);
  6714   6712       int bNoop = 0;
  6715   6713       RecoverTable *pTab;
  6716   6714   
  6717   6715       pTab = recoverFindTable(pState, &rc, iRoot, bIntkey, nCol, &bNoop);
  6718   6716       if( bNoop || rc ) continue;
  6719         -    if( pTab==0 ) pTab = pOrphan;
         6717  +    if( pTab==0 ){
         6718  +      if( pOrphan==0 ){
         6719  +        pOrphan = recoverOrphanTable(pState, &rc, zLostAndFound, nOrphan);
         6720  +      }
         6721  +      pTab = pOrphan;
         6722  +      if( pTab==0 ) break;
         6723  +    }
  6720   6724   
  6721   6725       if( 0==sqlite3_stricmp(pTab->zQuoted, "'sqlite_sequence'") ){
  6722   6726         raw_printf(pState->out, "DELETE FROM sqlite_sequence;\n");
  6723   6727       }
  6724   6728       sqlite3_bind_int(pPages, 1, iRoot);
  6725   6729       sqlite3_bind_int(pCells, 2, pTab->iPk);
  6726   6730