]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: avoid segfault validating a sgi label (boot/swap not set)
authorFrancesco Cosoleto <cosoleto@gmail.com>
Mon, 14 Nov 2011 13:47:18 +0000 (14:47 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 14 Nov 2011 14:07:18 +0000 (15:07 +0100)
swap_part or boot_part can be set to -1 when they don't exist.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
fdisk/fdisksgilabel.c
fdisk/fdisksgilabel.h

index 091902ab0ab800bf06929e5a96976ec0c450587f..002688a4cc0e84cce2fc5112f3a410d55b17f4de 100644 (file)
@@ -262,13 +262,13 @@ sgi_get_sysid(int i)
 int
 sgi_get_bootpartition(void)
 {
-       return SSWAP16(sgilabel->boot_part);
+       return (short) SSWAP16(sgilabel->boot_part);
 }
 
 int
 sgi_get_swappartition(void)
 {
-       return SSWAP16(sgilabel->swap_part);
+       return (short) SSWAP16(sgilabel->swap_part);
 }
 
 void
@@ -513,10 +513,10 @@ verify_sgi(int verbose)
         * Go for details now
         */
        if (verbose) {
-               if (!sgi_get_num_sectors(sgi_get_bootpartition())) {
+               if (sgi_get_bootpartition() < 0 || !sgi_get_num_sectors(sgi_get_bootpartition())) {
                        printf(_("\nThe boot partition does not exist.\n"));
                }
-               if (!sgi_get_num_sectors(sgi_get_swappartition())) {
+               if (sgi_get_swappartition() < 0 || !sgi_get_num_sectors(sgi_get_swappartition())) {
                        printf(_("\nThe swap partition does not exist.\n"));
                } else {
                        if ((sgi_get_sysid(sgi_get_swappartition()) != SGI_SWAP)
index 1445fa94a96f891e4ec22120a095f32fc4dad73b..1c47bb4742665aab137eb8be7c1821dd7eab399c 100644 (file)
@@ -63,8 +63,8 @@ struct device_parameter { /* 48 bytes */
 
 typedef struct {
        unsigned int   magic;            /* expect SGI_LABEL_MAGIC */
-       unsigned short boot_part;        /* active boot partition */
-       unsigned short swap_part;        /* active swap partition */
+       short boot_part;                /* active boot partition */
+       short swap_part;                /* active swap partition */
        unsigned char  boot_file[16];    /* name of the bootfile */
        struct device_parameter devparam;       /*  1 * 48 bytes */
        struct volume_directory {               /* 15 * 16 bytes */