From d3dd9020f585b8f587d9f2deb377750dbd260db1 Mon Sep 17 00:00:00 2001 From: Daniel Ramos Date: Sun, 15 Mar 2015 00:12:26 +0000 Subject: -fixed out of bounds crash when retrieving the main profile name with secret keys -fixed a possible crash when retrieving the main profile contactid --- .../keychain/util/ContactHelper.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index c07d7a36b..3fa6ea666 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -222,18 +222,20 @@ public class ContactHelper { * @return */ public static long getMainProfileContactId(ContentResolver resolver) { - Cursor profileCursor = resolver.query( - ContactsContract.Profile.CONTENT_URI, - new String[]{ - ContactsContract.Profile._ID - }, - null, null, null); - if (profileCursor == null) { + Cursor profileCursor = resolver.query(ContactsContract.Profile.CONTENT_URI, + new String[]{ ContactsContract.Profile._ID}, null, null, null); + + if(profileCursor != null && profileCursor.getCount() != 0 && profileCursor.moveToNext()) { + long contactId = profileCursor.getLong(0); + profileCursor.close(); + return contactId; + } + else { + if(profileCursor != null) { + profileCursor.close(); + } return -1; } - - profileCursor.moveToNext(); - return profileCursor.getLong(0); } /** -- cgit v1.2.3