From: Benjamin Kaduk Date: Thu, 24 Jul 2014 13:40:21 +0000 (-0400) Subject: Make kernel hcrypto calloc return zeroed memory X-Git-Tag: upstream/1.8.0_pre1^2~617 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=64da7c133a66a15233c2cdc5d9a8f71d17d80d77;p=packages%2Fo%2Fopenafs.git Make kernel hcrypto calloc return zeroed memory As far as I can tell, the afs_osi_Alloc contract does not guarantee zeroed memory. On FreeBSD, with a debug kernel, it definitely does not currently provide zeroed memory, returning instead memory initialized with 0xdeadc0de. Properly speaking, the role of calloc() is to both check for overflow from the multiplication and to produce zeroed memory. However, since we do not have a reasonable way to report failure, do not bother checking for overflow at this time. Change-Id: I187c2057d473fba869692c1dfa11735502b260c1 Reviewed-on: http://gerrit.openafs.org/11322 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Jeffrey Altman --- diff --git a/src/crypto/hcrypto/kernel/alloc.c b/src/crypto/hcrypto/kernel/alloc.c index 794d860db..2ae1172eb 100644 --- a/src/crypto/hcrypto/kernel/alloc.c +++ b/src/crypto/hcrypto/kernel/alloc.c @@ -28,8 +28,13 @@ void * _afscrypto_calloc(int num, size_t len) { void *ptr; + size_t total; - ptr = afs_osi_Alloc(num * len); + total = num * len; + ptr = afs_osi_Alloc(total); + /* In practice, callers assume the afs_osi_Alloc() will not fail. */ + if (ptr != NULL) + memset(ptr, 0, total); return ptr; }