[Pkg-gnupg-commit] [gnupg2] 65/292: tools: Convey signeddata also to the part_data callback in mime-parser.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Nov 21 06:31:26 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 c738f92c195d91662ddc7848cc3c92c7f091f1f8
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Sep 29 17:59:09 2016 +0200

    tools: Convey signeddata also to the part_data callback in mime-parser.
    
    * tools/mime-parser.c (mime_parser_parse): Factor some code out to ...
    (process_part_data): new.
    ((mime_parser_parse): Also call process_part_data for signed data.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 tools/mime-parser.c | 58 +++++++++++++++++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 20 deletions(-)

diff --git a/tools/mime-parser.c b/tools/mime-parser.c
index 0ca5452..9017810 100644
--- a/tools/mime-parser.c
+++ b/tools/mime-parser.c
@@ -616,6 +616,35 @@ mime_parser_rfc822parser (mime_parser_t ctx)
 }
 
 
+/* Helper for mime_parser_parse.  */
+static gpg_error_t
+process_part_data (mime_parser_t ctx, char *line, size_t *length)
+{
+  gpg_error_t err;
+  size_t nbytes;
+
+  if (!ctx->want_part)
+    return 0;
+  if (!ctx->part_data)
+    return 0;
+
+  if (ctx->decode_part == 1)
+    {
+      *length = qp_decode (line, *length, NULL);
+    }
+  else if (ctx->decode_part == 2)
+    {
+      log_assert (ctx->b64state);
+      err = b64dec_proc (ctx->b64state, line, *length, &nbytes);
+      if (err)
+        return err;
+      *length = nbytes;
+    }
+
+  return ctx->part_data (ctx->cookie, line, *length);
+}
+
+
 /* Read and parse a message from FP and call the appropriate
  * callbacks.  */
 gpg_error_t
@@ -624,7 +653,7 @@ mime_parser_parse (mime_parser_t ctx, estream_t fp)
   gpg_error_t err;
   rfc822parse_t msg = NULL;
   unsigned int lineno = 0;
-  size_t length, nbytes;
+  size_t length;
   char *line;
 
   line = ctx->line;
@@ -741,6 +770,10 @@ mime_parser_parse (mime_parser_t ctx, estream_t fp)
               ctx->collect_signeddata (ctx->cookie, line);
             }
           ctx->delay_hashing = 1;
+
+          err = process_part_data (ctx, line, &length);
+          if (err)
+            goto leave;
         }
       else if (ctx->pgpmime == PGPMIME_IN_SIGNATURE)
         {
@@ -756,26 +789,11 @@ mime_parser_parse (mime_parser_t ctx, estream_t fp)
           if (ctx->collect_signeddata)
             ctx->collect_signature (ctx->cookie, NULL);
         }
-      else if (ctx->want_part)
+      else
         {
-          if (ctx->part_data)
-            {
-              if (ctx->decode_part == 1)
-                {
-                  length = qp_decode (line, length, NULL);
-                }
-              else if (ctx->decode_part == 2)
-                {
-                  log_assert (ctx->b64state);
-                  err = b64dec_proc (ctx->b64state, line, length, &nbytes);
-                  if (err)
-                    goto leave;
-                  length = nbytes;
-                }
-              err = ctx->part_data (ctx->cookie, line, length);
-              if (err)
-                goto leave;
-            }
+          err = process_part_data (ctx, line, &length);
+          if (err)
+            goto leave;
         }
     }
 

-- 
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