From: Peng Fan Date: Tue, 12 Jan 2016 09:23:12 +0000 (+0800) Subject: common: env_flags: fix loop condition when using env_flags_varaccess_mask X-Git-Tag: v2016.03-rc1~314 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db18f548cb7b5ff99223b66eac1966eb45230817;p=platform%2Fkernel%2Fu-boot.git common: env_flags: fix loop condition when using env_flags_varaccess_mask 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. Signed-off-by: Peng Fan Cc: Joe Hershberger Cc: York Sun Cc: Simon Glass Cc: Tom Rini Reviewed-by: Simon Glass Acked-by: Joe Hershberger --- diff --git a/common/env_flags.c b/common/env_flags.c index 7719355..9c3aed1 100644 --- a/common/env_flags.c +++ b/common/env_flags.c @@ -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;