public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: Adrian Hunter <adrian.hunter@nokia.com>
Cc: "kyungmin.park@samsung.com" <kyungmin.park@samsung.com>,
	"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] onenand: test before subtraction on unsigned
Date: Wed, 04 Mar 2009 16:18:45 +0100	[thread overview]
Message-ID: <49AE9BD5.8000107@gmail.com> (raw)
In-Reply-To: <49AE950C.60907@nokia.com>

Adrian Hunter wrote:
> Roel Kluin wrote:
>> len is unsigned so will wrap around when sizeof(struct otp_info) is
>> greater than
>> len.

>> -            len -= sizeof(struct otp_info);
>> -            if (len <= 0) {
>> +            if (len <= sizeof(struct otp_info)) {
>> +                len = 0;
> 
> len is not used anymore, so no need to set it to zero.

Right, updated patch below.

>>                  ret = -ENOSPC;
>>                  break;
>>              }
>> +            len -= sizeof(struct otp_info);

> So is there somewhere that is passing a buffer too small for all the
> opt_info?

I don't know, I found it by code inspection.
------------------------------>8-------------8<---------------------------------
len is unsigned so will wrap around when sizeof(struct otp_info) is greater than
len.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 529af27..1219a18 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -2296,11 +2296,11 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,
 		if (!action) {	/* OTP Info functions */
 			struct otp_info *otpinfo;
 
-			len -= sizeof(struct otp_info);
-			if (len <= 0) {
+			if (len <= sizeof(struct otp_info)) {
 				ret = -ENOSPC;
 				break;
 			}
+			len -= sizeof(struct otp_info);
 
 			otpinfo = (struct otp_info *) buf;
 			otpinfo->start = from;

      reply	other threads:[~2009-03-04 15:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-04 14:09 [PATCH] onenand: test before subtraction on unsigned Roel Kluin
2009-03-04 14:49 ` Adrian Hunter
2009-03-04 15:18   ` Roel Kluin [this message]

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=49AE9BD5.8000107@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=adrian.hunter@nokia.com \
    --cc=akpm@linux-foundation.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-mtd@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox