gpg-interface: do not hardcode the key string len anymore
gnupg does print the keyid followed by a space and the signer comes next. The same pattern is also used in gpgsm, but there the key length would be 40 instead of 16. Instead of hardcoding the expected length, find the first space and calculate it. Input that does not match the expected format will be ignored now, before we jumped to found+17 which might have been behind the end of an unexpected string. Signed-off-by: Henning Schild <henning.schild@siemens.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Henning Schild committed
Jul 17, 2018 at 14:50 UTC
42149d7f4b1424b29c0bae4f564d5f50a856bcea
1 file changed
+4
-3
gpg-interface.c
+4
-3
@@ -95,10 +95,11 @@ static void parse_gpg_output(struct signature_check *sigc)
95
sigc->result = sigcheck_gpg_status[i].result;
96
/* The trust messages are not followed by key/signer information */
97
if (sigc->result != 'U') {
98
- sigc->key = xmemdupz(found, 16);
98
+ next = strchrnul(found, ' ');
99
+ sigc->key = xmemdupz(found, next - found);
100
/* The ERRSIG message is not followed by signer information */
100
- if (sigc-> result != 'E') {
101
- found += 17;
101
+ if (*next && sigc-> result != 'E') {
102
+ found = next + 1;
103
next = strchrnul(found, '\n');
104
sigc->signer = xmemdupz(found, next - found);
105
}