public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Roel Kluin <roel.kluin@gmail.com>
Cc: lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] udf: in scan_anchors() sector_t last[] is unsigned and cannot be negative.
Date: Wed, 3 Dec 2008 17:40:10 +0100	[thread overview]
Message-ID: <20081203164010.GA12803@duck.suse.cz> (raw)
In-Reply-To: <4935B249.6020906@gmail.com>

  Hello,

On Tue 02-12-08 23:10:17, Roel Kluin wrote:
> sector_t last[] is unsigned and cannot be negative.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
  Hmm, I think it would be a violation of the UDF standard if a we got a
medium where these numbers would underflow and most of the cases would
be caught by the following test. But let's make the code clean. I've
written the following patch (which I think makes the underflow checks
much more obvious):

>From a1ea42b47466b642c65cc6c3ca1a5a5fc18498ba Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
Date: Wed, 3 Dec 2008 17:31:39 +0100
Subject: [PATCH] udf: Add checks to not underflow sector_t

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/super.c |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index b9dc6ad..3c2d35d 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -731,13 +731,18 @@ static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock)
 	sector_t last[6];
 	int i;
 	struct udf_sb_info *sbi = UDF_SB(sb);
-
-	last[0] = lastblock;
-	last[1] = last[0] - 1;
-	last[2] = last[0] + 1;
-	last[3] = last[0] - 2;
-	last[4] = last[0] - 150;
-	last[5] = last[0] - 152;
+	int last_count = 0;
+
+	last[last_count++] = lastblock;
+	if (lastblock >= 1)
+		last[last_count++] = lastblock - 1;
+	last[last_count++] = lastblock + 1;
+	if (lastblock >= 2)
+		last[last_count++] = lastblock - 2;
+	if (lastblock >= 150)
+		last[last_count++] = lastblock - 150;
+	if (lastblock >= 152)
+		last[last_count++] = lastblock - 152;
 
 	/*  according to spec, anchor is in either:
 	 *     block 256
@@ -745,7 +750,7 @@ static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock)
 	 *     lastblock
 	 *  however, if the disc isn't closed, it could be 512 */
 
-	for (i = 0; i < ARRAY_SIZE(last); i++) {
+	for (i = 0; i < last_count; i++) {
 		if (last[i] >= sb->s_bdev->bd_inode->i_size >>
 				sb->s_blocksize_bits)
 			continue;
-- 
1.6.0.4


      reply	other threads:[~2008-12-03 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-02 22:10 [PATCH] udf: in scan_anchors() sector_t last[] is unsigned and cannot be negative Roel Kluin
2008-12-03 16:40 ` Jan Kara [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=20081203164010.GA12803@duck.suse.cz \
    --to=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roel.kluin@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox