From 901842d5221bcef539ec8d66109fbfaf3c8988ee Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 8 Jan 2009 19:51:59 +0000 Subject: [PATCH] Fix error detection --- sm/ChangeLog | 4 ++++ sm/fingerprint.c | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sm/ChangeLog b/sm/ChangeLog index b47b3a45b..dae0a544c 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,7 @@ +2009-01-08 Werner Koch + + * fingerprint.c (gpgsm_get_keygrip_hexstring): Add error detection. + 2008-12-10 Werner Koch * gpgsm.c (our_cipher_test_algo): Use the GCRY constants as we now diff --git a/sm/fingerprint.c b/sm/fingerprint.c index 1c65512a6..6581688a8 100644 --- a/sm/fingerprint.c +++ b/sm/fingerprint.c @@ -152,9 +152,9 @@ gpgsm_get_short_fingerprint (ksba_cert_t cert) /* Return the so called KEYGRIP which is the SHA-1 hash of the public - key parameters expressed as an canoncial encoded S-Exp. array must - be 20 bytes long. returns the array or a newly allocated one if the - passed one was NULL */ + key parameters expressed as an canoncial encoded S-Exp. ARRAY must + be 20 bytes long. Returns ARRAY or a newly allocated buffer if ARRAY was + given as NULL. May return NULL on error. */ unsigned char * gpgsm_get_keygrip (ksba_cert_t cert, unsigned char *array) { @@ -204,9 +204,11 @@ gpgsm_get_keygrip_hexstring (ksba_cert_t cert) unsigned char grip[20]; char *buf; - gpgsm_get_keygrip (cert, grip); - buf = xmalloc (20*2+1); - bin2hex (grip, 20, buf); + if (!gpgsm_get_keygrip (cert, grip)) + return NULL; + buf = xtrymalloc (20*2+1); + if (buf) + bin2hex (grip, 20, buf); return buf; }