All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <error27@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
	Steve Cornelius <sec@pobox.com>,
	Kim Phillips <kim.phillips@freescale.com>,
	linux-crypto@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] crypto: caam - ARRAY_SIZE() vs sizeof()
Date: Tue, 15 Mar 2011 06:59:55 +0000	[thread overview]
Message-ID: <20110315065955.GP2008@bicker> (raw)

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 {

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <error27@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
	Steve Cornelius <sec@pobox.com>,
	Kim Phillips <kim.phillips@freescale.com>,
	linux-crypto@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] crypto: caam - ARRAY_SIZE() vs sizeof()
Date: Tue, 15 Mar 2011 09:59:55 +0300	[thread overview]
Message-ID: <20110315065955.GP2008@bicker> (raw)

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 {

             reply	other threads:[~2011-03-15  6:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-15  6:59 Dan Carpenter [this message]
2011-03-15  6:59 ` [patch] crypto: caam - ARRAY_SIZE() vs sizeof() Dan Carpenter
2011-03-15 22:20 ` Kim Phillips
2011-03-15 22:20   ` Kim Phillips
2011-03-23 13:22   ` Herbert Xu
2011-03-23 13:22     ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110315065955.GP2008@bicker \
    --to=error27@gmail.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=kim.phillips@freescale.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=sec@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.