[Pkg-gnupg-commit] [gnupg2] 153/292: agent: Slightly change structure of cmd_readkey.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit fdb653a33ea1a24d1159880624dbbcc0867865b5
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Oct 24 12:55:21 2016 +0200

    agent: Slightly change structure of cmd_readkey.
    
    * agent/command.c (cmd_readkey): Avoid a leave label in the middle of
    the code.  Remove the special return.
    --
    
    This helps to get better debug output.
    
    The set_error macro which is used by parse_keygrip merely sets the
    error code into the Assuan context.  It is thus no problem anymore to
    call leave_cmd after having used set_error.  This might havve been
    diffferent in the past.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 agent/command.c | 60 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/agent/command.c b/agent/command.c
index 1a13084..999f608 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -391,7 +391,9 @@ progress_cb (ctrl_t ctrl, const char *what, int printchar,
 }
 
 
-/* Helper to print a message while leaving a command.  */
+/* Helper to print a message while leaving a command.  Note that this
+ * function does not call assuan_set_error; the caller may do this
+ * prior to calling us.  */
 static gpg_error_t
 leave_cmd (assuan_context_t ctx, gpg_error_t err)
 {
@@ -1000,17 +1002,19 @@ cmd_readkey (assuan_context_t ctx, char *line)
   unsigned char grip[20];
   gcry_sexp_t s_pkey = NULL;
   unsigned char *pkbuf = NULL;
+  char *serialno = NULL;
   size_t pkbuflen;
+  const char *opt_card;
 
   if (ctrl->restricted)
     return leave_cmd (ctx, gpg_error (GPG_ERR_FORBIDDEN));
 
-  if (has_option_name (line, "--card"))
-    {
-      const char *keyid;
-      char *serialno = NULL;
+  opt_card = has_option_name (line, "--card");
+  line = skip_options (line);
 
-      keyid = skip_options (line);
+  if (opt_card)
+    {
+      const char *keyid = opt_card;
 
       rc = agent_card_getattr (ctrl, "SERIALNO", &serialno);
       if (rc)
@@ -1042,35 +1046,33 @@ cmd_readkey (assuan_context_t ctx, char *line)
         goto leave;
 
       rc = assuan_send_data (ctx, pkbuf, pkbuflen);
-
- leave:
-      xfree (serialno);
-      xfree (pkbuf);
-      gcry_sexp_release (s_pkey);
-      return leave_cmd (ctx, rc);
     }
-
-  rc = parse_keygrip (ctx, line, grip);
-  if (rc)
-    return rc; /* Return immediately as this is already an Assuan error code.*/
-
-  rc = agent_public_key_from_file (ctrl, grip, &s_pkey);
-  if (!rc)
+  else
     {
-      pkbuflen = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0);
-      assert (pkbuflen);
-      pkbuf = xtrymalloc (pkbuflen);
-      if (!pkbuf)
-        rc = gpg_error_from_syserror ();
-      else
+      rc = parse_keygrip (ctx, line, grip);
+      if (rc)
+        goto leave;
+
+      rc = agent_public_key_from_file (ctrl, grip, &s_pkey);
+      if (!rc)
         {
-          gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, pkbuf, pkbuflen);
-          rc = assuan_send_data (ctx, pkbuf, pkbuflen);
-          xfree (pkbuf);
+          pkbuflen = gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, NULL, 0);
+          log_assert (pkbuflen);
+          pkbuf = xtrymalloc (pkbuflen);
+          if (!pkbuf)
+            rc = gpg_error_from_syserror ();
+          else
+            {
+              gcry_sexp_sprint (s_pkey, GCRYSEXP_FMT_CANON, pkbuf, pkbuflen);
+              rc = assuan_send_data (ctx, pkbuf, pkbuflen);
+            }
         }
-      gcry_sexp_release (s_pkey);
     }
 
+ leave:
+  xfree (serialno);
+  xfree (pkbuf);
+  gcry_sexp_release (s_pkey);
   return leave_cmd (ctx, rc);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list