diff options
author | Werner Koch <[email protected]> | 2017-12-13 09:52:34 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-12-13 09:52:34 +0000 |
commit | cd26c5482b10bee7658959ae913f2ddb83190587 (patch) | |
tree | f57eb9c03f12f92eb15fd41485e04c5dc680993b /g10/keyid.c | |
parent | gpg: Remove some xmallocs. (diff) | |
download | gnupg-cd26c5482b10bee7658959ae913f2ddb83190587.tar.gz gnupg-cd26c5482b10bee7658959ae913f2ddb83190587.zip |
gpg: Return an error from hexfingerprint on malloc error.
* g10/keyid.c (hexfingerprint): Return NULL on malloc failure. Chnage
all callers.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/keyid.c')
-rw-r--r-- | g10/keyid.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/g10/keyid.c b/g10/keyid.c index d733156f8..ba35ec21f 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -790,12 +790,12 @@ fingerprint_from_pk (PKT_public_key *pk, byte *array, size_t *ret_len) /* Return an allocated buffer with the fingerprint of PK formatted as - a plain hexstring. If BUFFER is NULL the result is a malloc'd - string. If BUFFER is not NULL the result will be copied into this - buffer. In the latter case BUFLEN describes the length of the - buffer; if this is too short the function terminates the process. - Returns a malloc'ed string or BUFFER. A suitable length for BUFFER - is (2*MAX_FINGERPRINT_LEN + 1). */ + * a plain hexstring. If BUFFER is NULL the result is a malloc'd + * string. If BUFFER is not NULL the result will be copied into this + * buffer. In the latter case BUFLEN describes the length of the + * buffer; if this is too short the function terminates the process. + * Returns a malloc'ed string or BUFFER. A suitable length for BUFFER + * is (2*MAX_FINGERPRINT_LEN + 1). */ char * hexfingerprint (PKT_public_key *pk, char *buffer, size_t buflen) { @@ -804,7 +804,11 @@ hexfingerprint (PKT_public_key *pk, char *buffer, size_t buflen) fingerprint_from_pk (pk, fpr, &len); if (!buffer) - buffer = xmalloc (2 * len + 1); + { + buffer = xtrymalloc (2 * len + 1); + if (!buffer) + return NULL; + } else if (buflen < 2*len+1) log_fatal ("%s: buffer too short (%zu)\n", __func__, buflen); bin2hex (fpr, len, buffer); |