Merge branch 'dl/complete-cherry-pick-revert-skip'
[gitweb.git] / gpg-interface.c
index 1d33a7e9d4223a13a6d899b3b7af8d42073bdb38..d60115ca404edfedc492c55e5bc0f22fe0eaa5a2 100644 (file)
@@ -74,6 +74,7 @@ void signature_check_clear(struct signature_check *sigc)
        FREE_AND_NULL(sigc->signer);
        FREE_AND_NULL(sigc->key);
        FREE_AND_NULL(sigc->fingerprint);
+       FREE_AND_NULL(sigc->primary_key_fingerprint);
 }
 
 /* An exclusive status -- only one of them can appear in output */
@@ -108,13 +109,16 @@ static void parse_gpg_output(struct signature_check *sigc)
 {
        const char *buf = sigc->gpg_status;
        const char *line, *next;
-       int i;
+       int i, j;
        int seen_exclusive_status = 0;
 
        /* Iterate over all lines */
        for (line = buf; *line; line = strchrnul(line+1, '\n')) {
                while (*line == '\n')
                        line++;
+               if (!*line)
+                       break;
+
                /* Skip lines that don't start with GNUPG status */
                if (!skip_prefix(line, "[GNUPG:] ", &line))
                        continue;
@@ -123,7 +127,7 @@ static void parse_gpg_output(struct signature_check *sigc)
                for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
                        if (skip_prefix(line, sigcheck_gpg_status[i].check, &line)) {
                                if (sigcheck_gpg_status[i].flags & GPG_STATUS_EXCLUSIVE) {
-                                       if (++seen_exclusive_status > 1)
+                                       if (seen_exclusive_status++)
                                                goto found_duplicate_status;
                                }
 
@@ -147,6 +151,18 @@ static void parse_gpg_output(struct signature_check *sigc)
                                        next = strchrnul(line, ' ');
                                        free(sigc->fingerprint);
                                        sigc->fingerprint = xmemdupz(line, next - line);
+
+                                       /* Skip interim fields */
+                                       for (j = 9; j > 0; j--) {
+                                               if (!*next)
+                                                       break;
+                                               line = next + 1;
+                                               next = strchrnul(line, ' ');
+                                       }
+
+                                       next = strchrnul(line, '\n');
+                                       free(sigc->primary_key_fingerprint);
+                                       sigc->primary_key_fingerprint = xmemdupz(line, next - line);
                                }
 
                                break;
@@ -165,6 +181,7 @@ static void parse_gpg_output(struct signature_check *sigc)
         */
        sigc->result = 'E';
        /* Clear partial data to avoid confusion */
+       FREE_AND_NULL(sigc->primary_key_fingerprint);
        FREE_AND_NULL(sigc->fingerprint);
        FREE_AND_NULL(sigc->signer);
        FREE_AND_NULL(sigc->key);