From: Junio C Hamano Date: Tue, 17 Jul 2018 20:56:41 GMT Subject: Re: [PATCH v4 4/7] gpg-interface: do not hardcode the key string len anymore Message-ID: In-Reply-To: <8330bd5b90aec511e20d21cd0c466752e4ada4b1.1531831244.git.henning.schild@siemens.com> Henning Schild writes: > 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 > --- > gpg-interface.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) Again, really nice. > > diff --git a/gpg-interface.c b/gpg-interface.c > index a02db7658..51cad9081 100644 > --- a/gpg-interface.c > +++ b/gpg-interface.c > @@ -95,10 +95,11 @@ static void parse_gpg_output(struct signature_check *sigc) > sigc->result = sigcheck_gpg_status[i].result; > /* The trust messages are not followed by key/signer information */ > if (sigc->result != 'U') { > - sigc->key = xmemdupz(found, 16); > + next = strchrnul(found, ' '); > + sigc->key = xmemdupz(found, next - found); > /* The ERRSIG message is not followed by signer information */ > - if (sigc-> result != 'E') { > - found += 17; > + if (*next && sigc-> result != 'E') { > + found = next + 1; > next = strchrnul(found, '\n'); > sigc->signer = xmemdupz(found, next - found); > }