Skip to content

Commit

Permalink
Fix execution of problematic SQL scripts leading to empty commands
Browse files Browse the repository at this point in the history
This fixes the execution of those SQL scripts that by some way or
another are either containing or leading to empty commands. Most notably
this includes two consecurity semicolons and completely empty scripts.
  • Loading branch information
MKleusberg committed Feb 1, 2017
1 parent c683034 commit 934dd39
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/sqlitedb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
sqlite3_stmt* vm;
QByteArray utf8Query = query.toUtf8();
const char *tail = utf8Query.data();
int res = 0;
int res = SQLITE_OK;
unsigned int line = 0;
bool structure_updated = false;
do
while(tail && *tail != 0 && (res == SQLITE_OK || res == SQLITE_DONE))
{
line++;
size_t tail_length = strlen(tail);
Expand Down Expand Up @@ -733,6 +733,8 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
case SQLITE_OK:
case SQLITE_ROW:
case SQLITE_DONE:
case SQLITE_MISUSE: // This is a workaround around problematic user scripts. If they lead to empty commands,
// SQLite will return a misuse error which we hereby ignore.
sqlite3_finalize(vm);
break;
default:
Expand All @@ -757,7 +759,7 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
qWarning() << lastErrorMessage;
return false;
}
} while(tail && *tail != 0 && (res == SQLITE_OK || res == SQLITE_DONE));
}

// If the DB structure was changed by some command in this SQL script, update our schema representations
if(structure_updated)
Expand Down

0 comments on commit 934dd39

Please sign in to comment.