]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: don't fails silently if EBR is outside of disk
authorKarel Zak <kzak@redhat.com>
Fri, 30 Nov 2012 10:54:10 +0000 (11:54 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 30 Nov 2012 10:54:10 +0000 (11:54 +0100)
Reported-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.h
fdisks/fdiskdoslabel.c

index 90ebb620909f81b64f28077777848a8508173577..f8e2c5d6ff3e47bcb27585a1bb5e833d7874aa6e 100644 (file)
@@ -311,18 +311,22 @@ static inline void set_start_sect(struct partition *p, unsigned int start_sect)
        store4_little_endian(p->start4, start_sect);
 }
 
-static inline void seek_sector(struct fdisk_context *cxt, sector_t secno)
+static inline int seek_sector(struct fdisk_context *cxt, sector_t secno)
 {
        off_t offset = (off_t) secno * cxt->sector_size;
-       if (lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1)
-               fatal(cxt, unable_to_seek);
+
+       return lseek(cxt->dev_fd, offset, SEEK_SET) == (off_t) -1 ? -errno : 0;
 }
 
-static inline void read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf)
+static inline int read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf)
 {
-       seek_sector(cxt, secno);
-       if (read(cxt->dev_fd, buf, cxt->sector_size) != (ssize_t) cxt->sector_size)
-               fatal(cxt, unable_to_read);
+       int rc = seek_sector(cxt, secno);
+
+       if (rc < 0)
+               return rc;
+
+       return read(cxt->dev_fd, buf, cxt->sector_size) !=
+                       (ssize_t) cxt->sector_size ? -errno : 0;
 }
 
 static inline sector_t get_start_sect(struct partition *p)
index 3e56e3885b842a0dfbe68909173e631ff81e0d4b..0ace7f8462247953c0b4bcaf2ca9068a461a4c79 100644 (file)
@@ -69,7 +69,10 @@ static void read_pte(struct fdisk_context *cxt, int pno, sector_t offset)
 
        pe->offset = offset;
        pe->sectorbuffer = xmalloc(cxt->sector_size);
-       read_sector(cxt, offset, pe->sectorbuffer);
+
+       if (read_sector(cxt, offset, pe->sectorbuffer) != 0)
+               fprintf(stderr, _("Failed to read extended partition table (offset=%jd)\n"),
+                                       (uintmax_t) offset);
        pe->changed = 0;
        pe->part_table = pe->ext_pointer = NULL;
 }
@@ -790,7 +793,14 @@ static void dos_add_partition(
 static int write_sector(struct fdisk_context *cxt, sector_t secno,
                               unsigned char *buf)
 {
-       seek_sector(cxt, secno);
+       int rc;
+
+       rc = seek_sector(cxt, secno);
+       if (rc != 0) {
+               fprintf(stderr, _("write sector %jd failed: seek failed"),
+                               (uintmax_t) secno);
+               return rc;
+       }
        if (write(cxt->dev_fd, buf, cxt->sector_size) != (ssize_t) cxt->sector_size)
                return -errno;
        return 0;