Skip to contentSkip to conversation

FAT: get_fatent: Fix FAT boundary check

PATCH Superseded Benoît Thébaudeau 2 participants 3 messages Jul 19, 2012 – Sep 2, 2012 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 FAT: get_fatent: Fix FAT boundary check

startblock must be taken into account in order not to read past the end of the FAT.

---
 .../fs/fat/fat.c                                   |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fat/fat.c +2 -2
index bc46cc5..f6fd457 100644
@@ -207,8 +207,8 @@ static __u32 get_fatent (fsdata *mydata, __u32 entry)
 		__u32 fatlength = mydata->fatlength;
 		__u32 startblock = bufnum * FATBUFBLOCKS;
 
-		if (getsize > fatlength)
-			getsize = fatlength;
+		if (startblock + getsize > fatlength)
+			getsize = fatlength - startblock;
 
 		fatlength *= mydata->sect_size;	/* We want it in bytes now */
 		startblock += mydata->fat_sect;	/* Offset from start of disk */
#1 lore raw

PATCH v2 2/8 FAT: get_fatent: Fix FAT boundary check

startblock must be taken into account in order not to read past the end of the FAT.

---
Changes for v2:
- Patch renumbering because of the new v2 1/8.
- Possible code style changes due to the new v2 1/8.

 .../fs/fat/fat.c                                   |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/fat/fat.c +2 -2
index 9f83572..87a1623 100644
@@ -207,8 +207,8 @@ static __u32 get_fatent(fsdata *mydata, __u32 entry)
 		__u32 fatlength = mydata->fatlength;
 		__u32 startblock = bufnum * FATBUFBLOCKS;
 
-		if (getsize > fatlength)
-			getsize = fatlength;
+		if (startblock + getsize > fatlength)
+			getsize = fatlength - startblock;
 
 		fatlength *= mydata->sect_size;	/* We want it in bytes now */
 		startblock += mydata->fat_sect;	/* Offset from start of disk */
#2 lore raw

PATCH v2 2/8 FAT: get_fatent: Fix FAT boundary check

Dear Beno?t Th?baudeau,

Quoted 6 lines · In message <[email protected]> you…

startblock must be taken into account in order not to read past the end of = the
FAT.

Quoted 7 lines

---
Changes for v2:
- Patch renumbering because of the new v2 1/8.
- Possible code style changes due to the new v2 1/8.

 .../fs/fat/fat.c                                   |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Any sufficiently advanced technology is indistinguishable from magic.
Clarke's Third Law       - _Profiles of the Future_ (1962; rev. 1973)
                  ``Hazards of Prophecy: The Failure of Imagination''