mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
crypto/hash: avoid overwriting user supplied result pointer
If the user provides a pre-allocated buffer for the hash result, we must use that rather than re-allocating a new buffer. Reported-by: Dorjoy Chowdhury <dorjoychy111@gmail.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
b5b89e9bc6
commit
dde538c9a7
4 changed files with 44 additions and 10 deletions
|
@ -99,8 +99,15 @@ int qcrypto_glib_hash_finalize(QCryptoHash *hash,
|
|||
return -1;
|
||||
}
|
||||
|
||||
*result_len = ret;
|
||||
*result = g_new(uint8_t, *result_len);
|
||||
if (*result_len == 0) {
|
||||
*result_len = ret;
|
||||
*result = g_new(uint8_t, *result_len);
|
||||
} else if (*result_len != ret) {
|
||||
error_setg(errp,
|
||||
"Result buffer size %zu is smaller than hash %d",
|
||||
*result_len, ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_checksum_get_digest(ctx, *result, result_len);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue