Skip to content

Commit

Permalink
crypto: caam - ARRAY_SIZE() vs sizeof()
Browse files Browse the repository at this point in the history
ARRAY_SIZE() was intended here instead of sizeof().  sizeof() is four
times larger than ARRAY_SIZE().  outstr is normally 256 chars so 
printing garbage to it could overfill the buffer and corrupt memory.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Acked-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Dan Carpenter authored and Herbert Xu committed Mar 27, 2011
1 parent cdc712d commit 6d00376
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/crypto/caam/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ static void report_ccb_status(u32 status, char *outstr)

report_jump_idx(status, outstr);

if (cha_id < sizeof(cha_id_list)) {
if (cha_id < ARRAY_SIZE(cha_id_list)) {
SPRINTFCAT(outstr, "%s: ", cha_id_list[cha_id],
strlen(cha_id_list[cha_id]));
} else {
SPRINTFCAT(outstr, "unidentified cha_id value 0x%02x: ",
cha_id, sizeof("ff"));
}

if (err_id < sizeof(err_id_list)) {
if (err_id < ARRAY_SIZE(err_id_list)) {
SPRINTFCAT(outstr, "%s", err_id_list[err_id],
strlen(err_id_list[err_id]));
} else {
Expand Down Expand Up @@ -198,11 +198,11 @@ static void report_deco_status(u32 status, char *outstr)

report_jump_idx(status, outstr);

for (i = 0; i < sizeof(desc_error_list); i++)
for (i = 0; i < ARRAY_SIZE(desc_error_list); i++)
if (desc_error_list[i].value == desc_error)
break;

if (i != sizeof(desc_error_list) && desc_error_list[i].error_text) {
if (i != ARRAY_SIZE(desc_error_list) && desc_error_list[i].error_text) {
SPRINTFCAT(outstr, "%s", desc_error_list[i].error_text,
strlen(desc_error_list[i].error_text));
} else {
Expand Down

0 comments on commit 6d00376

Please sign in to comment.