[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#674060: Doesn't support reading InRelease files



On 31/05/12 12:17, Bastian Blank wrote:
On Fri, May 25, 2012 at 11:01:57AM +0200, Mehdi Dogguy wrote:
index 67aa412..0b0f802 100644
--- a/src/parser_rfc822.c
+++ b/src/parser_rfc822.c
@@ -60,6 +60,7 @@ int di_parser_rfc822_read (char *begin, size_t size, di_parser_info *info, di_pa
    di_rstring field_modifier_string;
    di_rstring value_string;
    void *act = NULL;
+  int pgp_mode = 0;

    cur = begin;
    end = begin + size;
@@ -81,6 +82,25 @@ int di_parser_rfc822_read (char *begin, size_t size, di_parser_info *info, di_pa

      while (1)
      {
+      if (!strncmp(cur, "-----BEGIN PGP SIGNED MESSAGE-----", 34))

Please don't use magic numbers.
| const char pgp_begin = "…";
| if (!strncmp(cur, pgp_begin, strlen(pgp_begin))
or something like that. The strlen call should be optimized away.

Also this string may only appear at the beginning of the file, not
somewhere in between. So this should be done before the large loop.
Also the end of the preamble can be searched with \n\n.

+      else if (pgp_mode&&  !strncmp(cur, "-----BEGIN PGP SIGNATURE-----", 29))
+      {
+        // Let's exit, the rest of the file is not interesting
+        cur += size;
+        break;
+      }

Okay.


Thanks for the review! Please find attached an updated patch taking
into consideration your remarks.

Cheers,

--
Mehdi Dogguy مهدي الدڤي
http://dogguy.org/
>From c0b6669243e2282e0010d74790373764fe77b5ab Mon Sep 17 00:00:00 2001
From: Mehdi Dogguy <mehdi@debian.org>
Date: Wed, 23 May 2012 13:18:59 +0200
Subject: [PATCH] Add support for InRelease files (Closes: #674060)

---
 src/parser_rfc822.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/parser_rfc822.c b/src/parser_rfc822.c
index 67aa412..eca63c6 100644
--- a/src/parser_rfc822.c
+++ b/src/parser_rfc822.c
@@ -60,6 +60,9 @@ int di_parser_rfc822_read (char *begin, size_t size, di_parser_info *info, di_pa
   di_rstring field_modifier_string;
   di_rstring value_string;
   void *act = NULL;
+  int pgp_mode = 0;
+  const char *pgp_begin_msg = "-----BEGIN PGP SIGNED MESSAGE-----";
+  const char *pgp_begin_sig = "-----BEGIN PGP SIGNATURE-----";
 
   cur = begin;
   end = begin + size;
@@ -72,6 +75,15 @@ int di_parser_rfc822_read (char *begin, size_t size, di_parser_info *info, di_pa
       continue;
     }
 
+    if (!strncmp(cur, pgp_begin_msg, strlen(pgp_begin_msg)))
+    {
+      // Enable pgp_mode
+      pgp_mode = 1;
+      // Skip PGP header
+      cur = strstr (cur, "\n\n");
+      cur += 2;
+    }
+
     nr++;
 
     if (entry_new)
@@ -81,6 +93,12 @@ int di_parser_rfc822_read (char *begin, size_t size, di_parser_info *info, di_pa
 
     while (1)
     {
+      if (pgp_mode && !strncmp(cur, pgp_begin_sig, strlen(pgp_begin_sig)))
+      {
+        // Let's exit, the rest of the file is not interesting
+        cur += size;
+        break;
+      }
       field_begin = cur;
       readsize = end - field_begin < READSIZE ? end - field_begin : READSIZE;
       if (!readsize)
-- 
1.7.10


Reply to: