Skip to contentSkip to conversation

crypto/testmgr.c: fix sizeof() on COMP_BUF_SIZE

PATCH In review Michael Schupikov 3 participants 3 messages Oct 7, 2018 – Oct 12, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto/testmgr.c: fix sizeof() on COMP_BUF_SIZE

After allocation, output and decomp_output both point to memory chunks of size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using sizeof(COMP_BUF_SIZE) as parameter to memset(), because sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of allocated memory.

Instead, the whole allocated memory is meant to be zeroed out. Use COMP_BUF_SIZE as parameter to memset() directly in order to accomplish this.

Fixes 336073840a872 ("crypto: testmgr - Allow different compression results")
---
 crypto/testmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
crypto/testmgr.c +3 -3
index a1d42245082a..790aa3536631 100644
@@ -1400,8 +1400,8 @@ static int test_comp(struct crypto_comp *tfm,
 		int ilen;
 		unsigned int dlen = COMP_BUF_SIZE;
 
-		memset(output, 0, sizeof(COMP_BUF_SIZE));
-		memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+		memset(output, 0, COMP_BUF_SIZE);
+		memset(decomp_output, 0, COMP_BUF_SIZE);
 
 		ilen = ctemplate[i].inlen;
 		ret = crypto_comp_compress(tfm, ctemplate[i].input,
@@ -1445,7 +1445,7 @@ static int test_comp(struct crypto_comp *tfm,
 		int ilen;
 		unsigned int dlen = COMP_BUF_SIZE;
 
-		memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+		memset(decomp_output, 0, COMP_BUF_SIZE);
 
 		ilen = dtemplate[i].inlen;
 		ret = crypto_comp_decompress(tfm, dtemplate[i].input,
Signature · 1 line
2.19.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Michael Schupikov

After allocation, output and decomp_output both point to memory chunks of size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using sizeof(COMP_BUF_SIZE) as parameter to memset(), because sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of allocated memory.

Quoted 7 lines

Instead, the whole allocated memory is meant to be zeroed out. Use COMP_BUF_SIZE as parameter to memset() directly in order to accomplish this.

Fixes 336073840a872 ("crypto: testmgr - Allow different compression results")

Nice catch

Quoted 31 lines
---
 crypto/testmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
crypto/testmgr.c +3 -4
index a1d42245082a..790aa3536631 100644
@@ -1400,8 +1400,8 @@ static int test_comp(struct crypto_comp *tfm,
                int ilen;
                unsigned int dlen = COMP_BUF_SIZE;
 
-               memset(output, 0, sizeof(COMP_BUF_SIZE));
-               memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+               memset(output, 0, COMP_BUF_SIZE);
+               memset(decomp_output, 0, COMP_BUF_SIZE);
 
                ilen = ctemplate[i].inlen;
                ret = crypto_comp_compress(tfm, ctemplate[i].input,
@@ -1445,7 +1445,7 @@ static int test_comp(struct crypto_comp *tfm,
                int ilen;
                unsigned int dlen = COMP_BUF_SIZE;
 
-               memset(decomp_output, 0, sizeof(COMP_BUF_SIZE));
+               memset(decomp_output, 0, COMP_BUF_SIZE);
 
                ilen = dtemplate[i].inlen;
                ret = crypto_comp_decompress(tfm, dtemplate[i].input,
--

2.19.0

maintainer
#2 lore raw
In reply to Michael Schupikov
Quoted 10 lines · Michael Schupikov

After allocation, output and decomp_output both point to memory chunks of size COMP_BUF_SIZE. Then, only the first bytes are zeroed out using sizeof(COMP_BUF_SIZE) as parameter to memset(), because sizeof(COMP_BUF_SIZE) provides the size of the constant and not the size of allocated memory.

Instead, the whole allocated memory is meant to be zeroed out. Use COMP_BUF_SIZE as parameter to memset() directly in order to accomplish this.

Quoted 6 lines
Fixes 336073840a872 ("crypto: testmgr - Allow different compression results")
---
 crypto/testmgr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt