From: Junio C Hamano Date: Fri, 06 Jul 2018 20:22:42 GMT Subject: Re: [PATCH 6/8] gpg-interface: do not hardcode the key string len anymore Message-ID: In-Reply-To: <0d83d4d5c1c90011db90947d767ea0191a7ecbd7.1530616446.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. > > Signed-off-by: Henning Schild > --- > gpg-interface.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > Nicely explained and nicely implemented. > diff --git a/gpg-interface.c b/gpg-interface.c > index cd3b1b568..aa747278e 100644 > --- a/gpg-interface.c > +++ b/gpg-interface.c > @@ -88,10 +88,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; > + found = next + 1; > next = strchrnul(found, '\n'); > sigc->signer = xmemdupz(found, next - found); > }