fdisk: fix segfault on bsd label
PATCH 1/1 fdisk: fix segfault on bsd label
From: Davidlohr Bueso <[email protected]>
Commit 8db8295d824cd0c8cba9385e4635d6e311d69d3f added a regression that causes the program to crash when touching the partition structure (pte) for BSD/OSF labels. Since DOS has its own initialization function, allow BSD labels to use it as well.
Steps to reproduce:
$> fdisk bsd.img (obtained from blkid regression test files) Command (m for help): p
...
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
Segmentation fault
---
As discussed, this is a temporary fix, a nicer way of initializing bsd structures will be implemented in the short future.
fdisk/fdisk.c | 2 ++ fdisk/fdiskdoslabel.c | 2 +- fdisk/fdiskdoslabel.h | 1 + 3 files changed, 4 insertions(+), 1 deletions(-)
fdisk/fdisk.c +2 -0
@@ -763,6 +763,8 @@ static int get_boot(int try_only) {return 0 ;if (check_osf_label ()) { +/* intialize partitions for BSD as well */ +dos_init ();if (!valid_part_table_flag (MBRbuffer)) { disklabel =OSF_LABEL ;return 0 ;
fdisk/fdiskdoslabel.c +1 -1
@@ -54,7 +54,7 @@ static void clear_partition(struct partition *p)set_nr_sects (p,0 ); } -static void dos_init (void ) +void dos_init (void ) {int i;
fdisk/fdiskdoslabel.h +1 -0
@@ -48,5 +48,6 @@ extern void dos_set_mbr_id(void);extern void dos_delete_partition (int i);extern int check_dos_label (void );extern int is_dos_partition (int t); +extern void dos_init (void );#endif
Signature · 1 line
1.7.8.3
2012/5/4 Davidlohr Bueso <[email protected]>:
Quoted 8 lines
From: Davidlohr Bueso <[email protected]>
Commit
8db8295d824cd0c8cba9385e4635d6e311d69d3fadded a regression that causes the program to crash when touching the partition structure (pte) for BSD/OSF labels. Since DOS has its own initialization function, allow BSD labels to use it as well.Steps to reproduce:
Quoted 7 lines
$> fdisk bsd.img (obtained from blkid regression test files) Command (m for help): p
...
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier:0x00000000Segmentation fault
Thanks Davidlohr for pointing out that regression. Does it occurs with the command to print the partition table when the drive has a BSD label and hasn't a valid DOS label, and it has no partition? Fdisk switches from BSD label to DOS label without initializing DOS structures, right?
fdisk.c:
bsd_command_prompt();
/* If we return we may want to make an empty DOS label? */
disklabel = DOS_LABEL;Quoted 31 lines · Francesco Cosoleto
2012/5/4 Davidlohr Bueso <[email protected]>:
Quoted 8 lines
From: Davidlohr Bueso <[email protected]>
Commit
8db8295d824cd0c8cba9385e4635d6e311d69d3fadded a regression that causes the program to crash when touching the partition structure (pte) for BSD/OSF labels. Since DOS has its own initialization function, allow BSD labels to use it as well.Steps to reproduce:
Quoted 7 lines
$> fdisk bsd.img (obtained from blkid regression test files) Command (m for help): p
...
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier:0x00000000Segmentation fault
Thanks Davidlohr for pointing out that regression. Does it occurs with the command to print the partition table when the drive has a BSD label and hasn't a valid DOS label, and it has no partition? Fdisk switches from BSD label to DOS label without initializing DOS structures, right?
From my analysis, yes.
fdisk.c:bsd_command_prompt(); /* If we return we may want to make an empty DOS label? */ disklabel = DOS_LABEL;
Karel Zak
maintainerQuoted 18 lines · Davidlohr Bueso
Quoted 17 lines · Francesco Cosoleto
2012/5/4 Davidlohr Bueso <[email protected]>:
Quoted 15 lines
From: Davidlohr Bueso <[email protected]>
Commit
8db8295d824cd0c8cba9385e4635d6e311d69d3fadded a regression that causes the program to crash when touching the partition structure (pte) for BSD/OSF labels. Since DOS has its own initialization function, allow BSD labels to use it as well.Steps to reproduce:
$> fdisk bsd.img (obtained from blkid regression test files) Command (m for help): p
...
I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier:0x00000000Segmentation fault
Quoted 7 lines
Quoted 5 lines
Thanks Davidlohr for pointing out that regression. Does it occurs with the command to print the partition table when the drive has a BSD label and hasn't a valid DOS label, and it has no partition? Fdisk switches from BSD label to DOS label without initializing DOS structures, right?
From my analysis, yes.
Just note that some labels are nested -- for example BSD, minix unixware, ... are subtypes (nested partition tables) within DOS.
This parent->child relationship will be also necessary to support in new fdisk API.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 4 lines · Davidlohr Bueso
fdisk/fdisk.c | 2 ++ fdisk/fdiskdoslabel.c | 2 +- fdisk/fdiskdoslabel.h | 1 + 3 files changed, 4 insertions(+), 1 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com