Skip to contentSkip to conversation

crypto: testmgr: change `guard` to unsigned char

PATCH Superseded Joey Pabalinas 3 participants 6 messages Jan 1, 2018 – Jan 12, 2018

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

PATCH 1/1 crypto: testmgr: change `guard` to unsigned char

When char is signed, storing the values 0xba (186) and 0xad (173) in the guard array produces signed overflow. Change the type of guard to unsigned char to remove undefined behavior.

---
 crypto/testmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/testmgr.c +1 -1
index 29d7020b8826faa3f0..e9a9faecf212bbd742 100644
@@ -185,7 +185,7 @@ static int ahash_partial_update(struct ahash_request **preq,
 	char *state;
 	struct ahash_request *req;
 	int statesize, ret = -EINVAL;
-	const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
+	const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
 
 	req = *preq;
 	statesize = crypto_ahash_statesize(
Signature · 1 line
2.15.1
#1 lore raw
Quoted 3 lines · Joey Pabalinas

When char is signed, storing the values 0xba (186) and 0xad (173) in the guard array produces signed overflow. Change the type of guard to unsigned char to remove undefined behavior.

[]

crypto/testmgr.c

Quoted 1 line
crypto/testmgr.c +0 -0

[]

crypto/testmgr.c static int ahash_partial_update(struct ahash_request **preq, · line 188

Quoted 6 lines
crypto/testmgr.c +1 -1
@@ -185,7 +185,7 @@ static int ahash_partial_update(struct ahash_request **preq,
 	char *state;
 	struct ahash_request *req;
 	int statesize, ret = -EINVAL;
-	const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
+	const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };

Might as well add static too

#2 lore raw
Quoted 3 lines · Joe Perches

Might as well add static too

That's a good idea; I'll make a v2.

Signature · 1 line
Joey Pabalinas
#3 lore raw

PATCH v2 1/1 crypto: testmgr: change `guard` to unsigned char

In reply to Joe Perches

When char is signed, storing the values 0xba (186) and 0xad (173) in the guard array produces signed overflow. Change the type of guard to static unsigned char to correct undefined behavior and reduce function stack usage.

---
 crypto/testmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/testmgr.c +1 -1
index 29d7020b8826faa3f0..44a85d4b3561acbca6 100644
@@ -185,7 +185,7 @@ static int ahash_partial_update(struct ahash_request **preq,
 	char *state;
 	struct ahash_request *req;
 	int statesize, ret = -EINVAL;
-	const char guard[] = { 0x00, 0xba, 0xad, 0x00 };
+	static const unsigned char guard[] = { 0x00, 0xba, 0xad, 0x00 };
 
 	req = *preq;
 	statesize = crypto_ahash_statesize(
Signature · 1 line
2.15.1
maintainer
#4 lore raw
Quoted 6 lines · Joey Pabalinas

When char is signed, storing the values 0xba (186) and 0xad (173) in the guard array produces signed overflow. Change the type of guard to static unsigned char to correct undefined behavior and reduce function stack usage.

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
#5 lore raw
Quoted 2 lines · Herbert Xu

Patch applied. Thanks.

No problem, cheers.

Signature · 1 line
Joey Pabalinas