Skip to contentSkip to conversation

common: env_flags: fix loop condition when using env_flags_varaccess_mask

PATCH In review Peng Fan 4 participants 4 messages Jan 12, 2016 – Jan 14, 2016

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 common: env_flags: fix loop condition when using env_flags_varaccess_mask

From: Peng Fan <[email protected]>

We should use ARRAY_SIZE, but not sizeof. The size of env_flags_varaccess_mask is 16bytes, but we only need 4 loops. If using 16 as the end condition, we may access memory that not belong to array env_flags_varaccess_mask.

Cc Joe Hershberger <[email protected]>
Cc York Sun <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 common/env_flags.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
common/env_flags.c +1 -1
index 7719355..9c3aed1 100644
@@ -152,7 +152,7 @@ enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags)
 {
 	int i;
 
-	for (i = 0; i < sizeof(env_flags_varaccess_mask); i++)
+	for (i = 0; i < ARRAY_SIZE(env_flags_varaccess_mask); i++)
 		if (env_flags_varaccess_mask[i] ==
 		    (binflags & ENV_FLAGS_VARACCESS_BIN_MASK))
 			return (enum env_flags_varaccess)i;
Signature · 1 line
2.6.2
#1 lore raw

PATCH 1/1 common: env_flags: fix loop condition when using env_flags_varaccess_mask

Quoted 7 lines · Peng Fan

From: Peng Fan <[email protected]>

We should use ARRAY_SIZE, but not sizeof. The size of env_flags_varaccess_mask is 16bytes, but we only need 4 loops. If using 16 as the end condition, we may access memory that not belong to array env_flags_varaccess_mask.

Quoted 8 lines
Cc Joe Hershberger <[email protected]>
Cc York Sun <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 common/env_flags.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#2 lore raw

PATCH 1/1 common: env_flags: fix loop condition when using env_flags_varaccess_mask

In reply to Peng Fan
Quoted 7 lines · Peng Fan

From: Peng Fan <[email protected]>

We should use ARRAY_SIZE, but not sizeof. The size of env_flags_varaccess_mask is 16bytes, but we only need 4 loops. If using 16 as the end condition, we may access memory that not belong to array env_flags_varaccess_mask.

Quoted 6 lines
Cc Joe Hershberger <[email protected]>
Cc York Sun <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>

---

#3 lore raw
In reply to Peng Fan
Quoted 7 lines · Peng Fan

From: Peng Fan <[email protected]>

We should use ARRAY_SIZE, but not sizeof. The size of env_flags_varaccess_mask is 16bytes, but we only need 4 loops. If using 16 as the end condition, we may access memory that not belong to array env_flags_varaccess_mask.

Quoted 7 lines

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160114/2883e166/attachment.sig>