[ccan] [PATCH 4/7] crypto/hmac_sha256: Remove undefined memset()
David Gibson
david at gibson.dropbear.id.au
Mon Apr 3 21:11:09 AEST 2017
A memset() with a zero length argument isn't well defined. It *might* be
a no-op, but then it might not. So, test for this case in
hmac_sha256_init().
Found by Coverity.
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
ccan/crypto/hmac_sha256/hmac_sha256.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ccan/crypto/hmac_sha256/hmac_sha256.c b/ccan/crypto/hmac_sha256/hmac_sha256.c
index 0392afe..70ca3b2 100644
--- a/ccan/crypto/hmac_sha256/hmac_sha256.c
+++ b/ccan/crypto/hmac_sha256/hmac_sha256.c
@@ -36,7 +36,9 @@ void hmac_sha256_init(struct hmac_sha256_ctx *ctx,
* appended with 44 zero bytes 0x00)
*/
memcpy(k_ipad, k, ksize);
- memset((char *)k_ipad + ksize, 0, HMAC_SHA256_BLOCKSIZE - ksize);
+ if (ksize < HMAC_SHA256_BLOCKSIZE)
+ memset((char *)k_ipad + ksize, 0,
+ HMAC_SHA256_BLOCKSIZE - ksize);
/*
* (2) XOR (bitwise exclusive-OR) the B byte string computed
--
2.9.3
More information about the ccan
mailing list