From 7d973359427394a00d1d8778b352b67c9ff486d6 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 24 Jan 2015 21:33:30 +0100 Subject: [PATCH] disk/AFsplitter: check argument validity before doing any allocs. This avoids possible memory leaks. Found by: Coverity scan. --- grub-core/disk/AFSplitter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/AFSplitter.c b/grub-core/disk/AFSplitter.c index 7e1bd5748..f5a8ddc61 100644 --- a/grub-core/disk/AFSplitter.c +++ b/grub-core/disk/AFSplitter.c @@ -72,13 +72,13 @@ AF_merge (const gcry_md_spec_t * hash, grub_uint8_t * src, grub_uint8_t * dst, grub_size_t i; grub_uint8_t *bufblock; + if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN || hash->mdlen == 0) + return GPG_ERR_INV_ARG; + bufblock = grub_zalloc (blocksize); if (bufblock == NULL) return GPG_ERR_OUT_OF_MEMORY; - if (hash->mdlen > GRUB_CRYPTO_MAX_MDLEN || hash->mdlen == 0) - return GPG_ERR_INV_ARG; - grub_memset (bufblock, 0, blocksize); for (i = 0; i < blocknumbers - 1; i++) {