Skip to contentSkip to conversation

part_dos: fix crash with big sector size

PATCH New Sergei Shtylyov 3 participants 4 messages Jun 3, 2011 – Jul 27, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 part_dos: fix crash with big sector size

Apple iPod nanos have sector sizes of 2 or 4 KiB, which crashes U-Boot when it tries to read the MBR into 512-byte buffer situated on stack. Instead use the variable length arrays to be safe with any large sector size.

---
The same change is probably needed for disk/part_amiga.c but I'm not really sure if Amiga supports USB... :-)

 disk/part_dos.c |    6 +++---
 disk/part_dos.h |    7 -------
 2 files changed, 3 insertions(+), 10 deletions(-)
disk/part_dos.c +3 -3
Index: u-boot/disk/part_dos.c
===================================================================
@@ -87,7 +87,7 @@ static int test_block_type(unsigned char
 
 int test_part_dos (block_dev_desc_t *dev_desc)
 {
-	unsigned char buffer[DEFAULT_SECTOR_SIZE];
+	unsigned char buffer[dev_desc->blksz];
 
 	if ((dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *) buffer) != 1) ||
 	    (buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) ||
@@ -102,7 +102,7 @@ int test_part_dos (block_dev_desc_t *dev
 static void print_partition_extended (block_dev_desc_t *dev_desc, int ext_part_sector, int relative,
 							   int part_num)
 {
-	unsigned char buffer[DEFAULT_SECTOR_SIZE];
+	unsigned char buffer[dev_desc->blksz];
 	dos_partition_t *pt;
 	int i;
 
@@ -166,7 +166,7 @@ static int get_partition_info_extended (
 				 int relative, int part_num,
 				 int which_part, disk_partition_t *info)
 {
-	unsigned char buffer[DEFAULT_SECTOR_SIZE];
+	unsigned char buffer[dev_desc->blksz];
 	dos_partition_t *pt;
 	int i;
 
disk/part_dos.h +0 -7
Index: u-boot/disk/part_dos.h
===================================================================
@@ -25,13 +25,6 @@
 #define _DISK_PART_DOS_H
 
 
-#ifdef CONFIG_ISO_PARTITION
-/* Make the buffers bigger if ISO partition support is enabled -- CD-ROMS
-   have 2048 byte blocks */
-#define DEFAULT_SECTOR_SIZE	2048
-#else
-#define DEFAULT_SECTOR_SIZE	512
-#endif
 #define DOS_PART_TBL_OFFSET	0x1be
 #define DOS_PART_MAGIC_OFFSET	0x1fe
 #define DOS_PBR_FSTYPE_OFFSET	0x36
#1 lore raw

PATCH 1/1 part_dos: fix crash with big sector size

Hello.

Quoted 5 lines · I wrote:

Apple iPod nanos have sector sizes of 2 or 4 KiB, which crashes U-Boot when it tries to read the MBR into 512-byte buffer situated on stack. Instead use the variable length arrays to be safe with any large sector size.

Wolfgang, have you forgotten about this patch? Do I need to resend?

WBR, Sergei

#2 lore raw

PATCH 1/1 part_dos: fix crash with big sector size

In reply to Sergei Shtylyov

Hello.

Quoted 9 lines · I wrote:

Apple iPod nanos have sector sizes of 2 or 4 KiB, which crashes U-Boot when it tries to read the MBR into 512-byte buffer situated on stack. Instead use the variable length arrays to be safe with any large sector size.

---
The same change is probably needed for disk/part_amiga.c but I'm not really sure if Amiga supports USB... :-)

Damn, the FAT code is also hardwired for 512-byte sectors. I wonder which
century we are in? :-)

WBR, Sergei

#3 lore raw

PATCH 1/1 part_dos: fix crash with big sector size

In reply to Sergei Shtylyov

Dear Sergei Shtylyov,

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

Apple iPod nanos have sector sizes of 2 or 4 KiB, which crashes U-Boot when it tries to read the MBR into 512-byte buffer situated on stack. Instead use the variable length arrays to be safe with any large sector size.

Quoted 7 lines

---
The same change is probably needed for disk/part_amiga.c but I'm not really sure if Amiga supports USB... :-)

 disk/part_dos.c |    6 +++---
 disk/part_dos.h |    7 -------
 2 files changed, 3 insertions(+), 10 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 5 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
You don't have to stay up nights to succeed; you have to  stay  awake
days.