diff options
author | Karel Zak | 2014-04-08 10:14:12 +0200 |
---|---|---|
committer | Karel Zak | 2014-04-08 10:14:12 +0200 |
commit | 11fe0448a0ea059d361d0f650b37c970704c6819 (patch) | |
tree | 791fb1a4b401208634314ed16b7bbafe01d9bcb4 /libfdisk/src/dos.c | |
parent | libsmartcols: improve docs (diff) | |
download | kernel-qcow2-util-linux-11fe0448a0ea059d361d0f650b37c970704c6819.tar.gz kernel-qcow2-util-linux-11fe0448a0ea059d361d0f650b37c970704c6819.tar.xz kernel-qcow2-util-linux-11fe0448a0ea059d361d0f650b37c970704c6819.zip |
libfdisk: (dos) make EBR parser more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/dos.c')
-rw-r--r-- | libfdisk/src/dos.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index b1b23350f..5287c945d 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -218,17 +218,23 @@ static int read_sector(struct fdisk_context *cxt, sector_t secno, unsigned char *buf) { int rc = seek_sector(cxt, secno); + ssize_t r; if (rc < 0) return rc; - return read(cxt->dev_fd, buf, cxt->sector_size) != - (ssize_t) cxt->sector_size ? -errno : 0; + r = read(cxt->dev_fd, buf, cxt->sector_size); + if (r == (ssize_t) cxt->sector_size) + return 0; + if (r < 0) + return -errno; + return -1; } /* Allocate a buffer and read a partition table sector */ static int read_pte(struct fdisk_context *cxt, size_t pno, sector_t offset) { + int rc; unsigned char *buf; struct pte *pe = self_pte(cxt, pno); @@ -242,9 +248,13 @@ static int read_pte(struct fdisk_context *cxt, size_t pno, sector_t offset) pe->sectorbuffer = buf; pe->private_sectorbuffer = 1; - if (read_sector(cxt, offset, pe->sectorbuffer) != 0) + rc = read_sector(cxt, offset, pe->sectorbuffer); + if (rc) { fdisk_warn(cxt, _("Failed to read extended partition table " "(offset=%ju)"), (uintmax_t) offset); + return rc; + } + pe->changed = 0; pe->pt_entry = pe->ex_entry = NULL; return 0; @@ -492,8 +502,9 @@ static void read_extended(struct fdisk_context *cxt, size_t ext) return; } - read_pte(cxt, cxt->label->nparts_max, - l->ext_offset + dos_partition_get_start(p)); + if (read_pte(cxt, cxt->label->nparts_max, l->ext_offset + + dos_partition_get_start(p))) + return; if (!l->ext_offset) l->ext_offset = dos_partition_get_start(p); |