提交 456ccc14 编写于 作者: J John Ferlan

util: Perform proper virRandomBytes return value checking

Document the return value of virRandomBytes as 0 or some errno value and
then make sure all callers make the proper checks.
上级 cf922bf8
......@@ -315,7 +315,7 @@ virCryptoGenerateRandom(size_t nbytes)
/* If we don't have gnutls_rnd(), we will generate a less cryptographically
* strong master buf from /dev/urandom.
*/
if ((ret = virRandomBytes(buf, nbytes)) < 0) {
if ((ret = virRandomBytes(buf, nbytes))) {
virReportSystemError(ret, "%s", _("failed to generate byte stream"));
VIR_FREE(buf);
return NULL;
......
......@@ -167,6 +167,8 @@ uint32_t virRandomInt(uint32_t max)
*
* Generate a stream of random bytes from /dev/urandom
* into @buf of size @buflen
*
* Returns 0 on success or an errno on failure
*/
int
virRandomBytes(unsigned char *buf,
......
......@@ -87,9 +87,11 @@ testCryptoEncrypt(const void *opaque)
VIR_ALLOC_N(iv, ivlen) < 0)
goto cleanup;
if (virRandomBytes(enckey, enckeylen) < 0 ||
virRandomBytes(iv, ivlen) < 0)
if (virRandomBytes(enckey, enckeylen) ||
virRandomBytes(iv, ivlen)) {
fprintf(stderr, "Failed to generate random bytes\n");
goto cleanup;
}
if (virCryptoEncryptData(data->algorithm, enckey, enckeylen, iv, ivlen,
data->input, data->inputlen,
......
......@@ -40,7 +40,7 @@ testRandomBytes(const void *unused ATTRIBUTE_UNUSED)
if (VIR_ALLOC_N(data, datalen) < 0)
return -1;
if (virRandomBytes(data, datalen) < 0) {
if (virRandomBytes(data, datalen)) {
fprintf(stderr, "Failed to generate random bytes");
goto cleanup;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册