[gmime] Protect against dereferencing a NULL subkey
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Protect against dereferencing a NULL subkey
- Date: Tue, 14 Mar 2017 23:59:11 +0000 (UTC)
commit b6bc2f8864778747762f56e08a3247109a39ebd5
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date: Tue Mar 14 19:57:12 2017 -0400
Protect against dereferencing a NULL subkey
gmime/gmime-gpgme-utils.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/gmime/gmime-gpgme-utils.c b/gmime/gmime-gpgme-utils.c
index a9cf380..61bbe73 100644
--- a/gmime/gmime-gpgme-utils.c
+++ b/gmime/gmime-gpgme-utils.c
@@ -97,8 +97,7 @@ g_mime_gpgme_passphrase_callback (void *hook, const char *uid_hint, const char *
}
-#define KEY_IS_OK(k) (!((k)->expired || (k)->revoked || \
- (k)->disabled || (k)->invalid))
+#define KEY_IS_OK(k) (!((k)->expired || (k)->revoked || (k)->disabled || (k)->invalid))
static gpgme_key_t
g_mime_gpgme_get_key_by_name (gpgme_ctx_t ctx, const char *name, gboolean secret, GError **err)
@@ -123,18 +122,18 @@ g_mime_gpgme_get_key_by_name (gpgme_ctx_t ctx, const char *name, gboolean secret
if (KEY_IS_OK (key)) {
subkey = key->subkeys;
- while (subkey && ((secret && !subkey->can_sign) ||
- (!secret && !subkey->can_encrypt)))
+ while (subkey && ((secret && !subkey->can_sign) || (!secret && !subkey->can_encrypt)))
subkey = subkey->next;
- if (subkey && KEY_IS_OK (subkey) &&
- (subkey->expires == 0 || subkey->expires > now))
- break;
-
- if (subkey->expired)
- errval = GPG_ERR_KEY_EXPIRED;
- else
- errval = GPG_ERR_BAD_KEY;
+ if (subkey) {
+ if (KEY_IS_OK (subkey) && (subkey->expires == 0 || subkey->expires > now))
+ break;
+
+ if (subkey->expired)
+ errval = GPG_ERR_KEY_EXPIRED;
+ else
+ errval = GPG_ERR_BAD_KEY;
+ }
} else {
if (key->expired)
errval = GPG_ERR_KEY_EXPIRED;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]