* [patch] crypto: caam - ARRAY_SIZE() vs sizeof()
@ 2011-03-15 6:59 Dan Carpenter
2011-03-15 22:20 ` Kim Phillips
0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2011-03-15 6:59 UTC (permalink / raw)
To: Herbert Xu
Cc: David S. Miller, Steve Cornelius, Kim Phillips, linux-crypto,
kernel-janitors
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>
diff --git a/drivers/crypto/caam/error.c b/drivers/crypto/caam/error.c
index bd57a68..7e2d54b 100644
--- a/drivers/crypto/caam/error.c
+++ b/drivers/crypto/caam/error.c
@@ -73,7 +73,7 @@ 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 {
@@ -81,7 +81,7 @@ static void report_ccb_status(u32 status, char *outstr)
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 {
@@ -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 {
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [patch] crypto: caam - ARRAY_SIZE() vs sizeof()
2011-03-15 6:59 [patch] crypto: caam - ARRAY_SIZE() vs sizeof() Dan Carpenter
@ 2011-03-15 22:20 ` Kim Phillips
2011-03-23 13:22 ` Herbert Xu
0 siblings, 1 reply; 3+ messages in thread
From: Kim Phillips @ 2011-03-15 22:20 UTC (permalink / raw)
To: Dan Carpenter
Cc: Herbert Xu, David S. Miller, Steve Cornelius, linux-crypto,
kernel-janitors
On Tue, 15 Mar 2011 09:59:55 +0300
Dan Carpenter <error27@gmail.com> wrote:
> 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>
Thanks Dan,
Kim
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [patch] crypto: caam - ARRAY_SIZE() vs sizeof()
2011-03-15 22:20 ` Kim Phillips
@ 2011-03-23 13:22 ` Herbert Xu
0 siblings, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2011-03-23 13:22 UTC (permalink / raw)
To: Kim Phillips
Cc: Dan Carpenter, David S. Miller, Steve Cornelius, linux-crypto,
kernel-janitors
On Tue, Mar 15, 2011 at 05:20:37PM -0500, Kim Phillips wrote:
> On Tue, 15 Mar 2011 09:59:55 +0300
> Dan Carpenter <error27@gmail.com> wrote:
>
> > 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>
Also applied. Thanks!
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-23 13:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-15 6:59 [patch] crypto: caam - ARRAY_SIZE() vs sizeof() Dan Carpenter
2011-03-15 22:20 ` Kim Phillips
2011-03-23 13:22 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox