fix sqlcipher_export handling of NULL parameters
This commit is contained in:
parent
ba14070de1
commit
cb71f53e8c
22
src/crypto.c
22
src/crypto.c
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue