aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java
diff options
context:
space:
mode:
authorDaniel Ramos <hiperzone@gmail.com>2015-03-15 00:12:26 +0000
committerDaniel Ramos <hiperzone@gmail.com>2015-03-15 00:12:26 +0000
commitd3dd9020f585b8f587d9f2deb377750dbd260db1 (patch)
tree29a54fcbf343be765be52f2ffa6bde0f9601da57 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java
parentf1b1ecae20edb40a0c9b48009075daf94af51d20 (diff)
downloadopen-keychain-d3dd9020f585b8f587d9f2deb377750dbd260db1.tar.gz
open-keychain-d3dd9020f585b8f587d9f2deb377750dbd260db1.tar.bz2
open-keychain-d3dd9020f585b8f587d9f2deb377750dbd260db1.zip
-fixed out of bounds crash when retrieving the main profile name with secret keys
-fixed a possible crash when retrieving the main profile contactid
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java22
1 files changed, 12 insertions, 10 deletions
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);
}
/**