Skip to content
Permalink
Browse files Browse the repository at this point in the history
fix sqlcipher_export handling of NULL parameters
  • Loading branch information
sjlombardo committed Jan 13, 2021
1 parent ba14070 commit cb71f53
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/crypto.c
Expand Up @@ -1075,13 +1075,29 @@ void sqlcipher_exportFunc(sqlite3_context *context, int argc, sqlite3_value **ar
goto end_of_export;
}

targetDb = (const char*) sqlite3_value_text(argv[0]);
sourceDb = (argc == 2) ? (char *) sqlite3_value_text(argv[1]) : "main";
if(sqlite3_value_type(argv[0]) == SQLITE_NULL) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("target database can't be NULL");
goto end_of_export;
}

targetDb = (const char*) sqlite3_value_text(argv[0]);
sourceDb = "main";

if(argc == 2) {
if(sqlite3_value_type(argv[1]) == SQLITE_NULL) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("target database can't be NULL");
goto end_of_export;
}
sourceDb = (char *) sqlite3_value_text(argv[1]);
}


/* if the name of the target is not main, but the index returned is zero
there is a mismatch and we should not proceed */
targetDb_idx = sqlcipher_find_db_index(db, targetDb);
if(targetDb_idx == 0 && sqlite3StrICmp("main", targetDb) != 0) {
if(targetDb_idx == 0 && targetDb != NULL && sqlite3StrICmp("main", targetDb) != 0) {
rc = SQLITE_ERROR;
pzErrMsg = sqlite3_mprintf("unknown database %s", targetDb);
goto end_of_export;
Expand Down
26 changes: 26 additions & 0 deletions test/sqlcipher-compatibility.test
Expand Up @@ -444,6 +444,32 @@ do_test export-error {
db close
file delete -force test.db

# verify sqlcipher_export with NULL parameters
do_test export-nulls {
sqlite_orig db test.db

catchsql {
SELECT sqlcipher_export(NULL);
}

} {1 {target database can't be NULL}}
db close
file delete -force test.db

do_test export-nulls {
sqlite_orig db test.db

catchsql {
SELECT sqlcipher_export('main', NULL);
}

} {1 {target database can't be NULL}}
db close
file delete -force test.db


# use the sqlcipher_export function

# use the sqlcipher_export function
# to copy a complicated database.
# tests autoincrement fields,
Expand Down

0 comments on commit cb71f53

Please sign in to comment.