card: Fix a NULL-ptr deref in key listings.
authorWerner Koch <wk@gnupg.org>
Thu, 7 Feb 2019 15:28:03 +0000 (16:28 +0100)
committerWerner Koch <wk@gnupg.org>
Thu, 7 Feb 2019 15:28:03 +0000 (16:28 +0100)
* tools/card-tool-keys.c (get_matching_keys): Fix segv.
* tools/gpg-card-tool.c (main): Init info.

Signed-off-by: Werner Koch <wk@gnupg.org>
tools/card-tool-keys.c
tools/gpg-card-tool.c

index e9edf98..4e057ad 100644 (file)
@@ -214,9 +214,12 @@ get_matching_keys (const unsigned char *keygrip, int protocol,
       err = get_matching_keys (keygrip, GNUPG_PROTOCOL_OPENPGP, &kb);
       if (!err || gpg_err_code (err) == GPG_ERR_NO_PUBKEY)
         {
-          *keyblock_tail = kb;
-          keyblock_tail = &kb->next;
-          kb = NULL;
+          if (!err)
+            {
+              *keyblock_tail = kb;
+              keyblock_tail = &kb->next;
+              kb = NULL;
+            }
           err = get_matching_keys (keygrip, GNUPG_PROTOCOL_CMS, &kb);
           if (!err)
             {
index 9170132..0dbf2b2 100644 (file)
@@ -309,7 +309,7 @@ main (int argc, char **argv)
     }
   else
     {
-      struct card_info_s info_buffer;
+      struct card_info_s info_buffer = { 0 };
       card_info_t info = &info_buffer;
 
       err = 0;
@@ -2968,7 +2968,7 @@ interactive_loop (void)
   int redisplay = 1;           /* Whether to redisplay the main info.  */
   int allow_admin = 0;         /* Whether admin commands are allowed.  */
   char *help_arg = NULL;       /* Argument of the HELP command.         */
-  struct card_info_s info_buffer;
+  struct card_info_s info_buffer = { 0 };
   card_info_t info = &info_buffer;
   char *p;
   int i;