summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2018-05-29 07:50:29 +0200
committerMichal Privoznik <mprivozn@redhat.com>2018-06-05 10:31:19 +0200
commita5865cdbeaeeddf9a2c7817237e07c79d6f93296 (patch)
tree80e6cc338cec6a857095d844a3822d2b9f1e78db
parentd4e66f76396f48dfe8137365a55cb3a869dec77a (diff)
downloadlibvirt-a5865cdbeaeeddf9a2c7817237e07c79d6f93296.tar.gz
virCryptoGenerateRandom: Explain gnults error
When generating random stream using gnults fails an error is reported. However, the error is not helpful as it contains only an integer error code (a negative number). Use gnutls_strerror() to turn the error code into a string explaining what went wrong. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
-rw-r--r--src/util/vircrypto.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/vircrypto.c b/src/util/vircrypto.c
index 930fa3b215..9879c31555 100644
--- a/src/util/vircrypto.c
+++ b/src/util/vircrypto.c
@@ -323,7 +323,8 @@ virCryptoEncryptData(virCryptoCipher algorithm,
* Since the gnutls_rnd could be missing, provide an alternate less
* secure mechanism to at least have something.
*
- * Returns pointer memory containing byte stream on success, NULL on failure
+ * Returns pointer memory containing byte stream on success,
+ * NULL on failure (with error reported)
*/
uint8_t *
virCryptoGenerateRandom(size_t nbytes)
@@ -338,7 +339,8 @@ virCryptoGenerateRandom(size_t nbytes)
/* Generate the byte stream using gnutls_rnd() if possible */
if ((rv = gnutls_rnd(GNUTLS_RND_RANDOM, buf, nbytes)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to generate byte stream, rv=%d"), rv);
+ _("failed to generate byte stream: %s"),
+ gnutls_strerror(rv));
VIR_FREE(buf);
return NULL;
}