Skip to content

Commit 13279c4

Browse files
Merge pull request #12 from brodybits/null-password-crash
DO NOT MERGE: Reproduce CRASH on null password char array
2 parents 92898bf + 64dcf09 commit 13279c4

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/main/java/net/zetetic/tests/QueryNonEncryptedDatabaseTest.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package net.zetetic.tests;
22

33
import android.database.Cursor;
4+
45
import net.sqlcipher.database.SQLiteDatabase;
56
import net.zetetic.ZeteticApplication;
67

8+
import android.util.Log;
9+
710
import java.io.File;
811
import java.io.IOException;
912

@@ -12,21 +15,43 @@ public class QueryNonEncryptedDatabaseTest extends SQLCipherTest {
1215
@Override
1316
public boolean execute(SQLiteDatabase database) {
1417

15-
boolean success = false;
18+
database.close();
19+
File unencryptedDatabase = ZeteticApplication.getInstance().getDatabasePath("unencrypted.db");
20+
1621
try {
17-
File unencryptedDatabase = ZeteticApplication.getInstance().getDatabasePath("unencrypted.db");
1822
ZeteticApplication.getInstance().extractAssetToDatabaseDirectory("unencrypted.db");
19-
database.close();
23+
} catch (IOException e) {
24+
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: caught IOException", e);
25+
return false;
26+
}
27+
28+
boolean success = false;
29+
30+
// XXX CRASHING:
31+
try {
32+
char[] nullPassword = null;
33+
database = SQLiteDatabase.openOrCreateDatabase(unencryptedDatabase.getPath(), nullPassword, null, null);
34+
} catch (Exception e) {
35+
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: exception", e);
36+
return false;
37+
}
38+
39+
try {
2040
database = SQLiteDatabase.openOrCreateDatabase(unencryptedDatabase, "", null);
2141
Cursor cursor = database.rawQuery("select * from t1", new String[]{});
2242
cursor.moveToFirst();
2343
String a = cursor.getString(0);
2444
String b = cursor.getString(1);
2545
cursor.close();
2646
database.close();
47+
2748
success = a.equals("one for the money") &&
2849
b.equals("two for the show");
29-
} catch (IOException e) {}
50+
} catch (Exception e) {
51+
Log.e(ZeteticApplication.TAG, "NOT EXPECTED: exception when reading database with blank password", e);
52+
return false;
53+
}
54+
3055
return success;
3156
}
3257

0 commit comments

Comments
 (0)