Don't assign the sector buffer to the partition table entry until
read_sector() succeeds. On failure, free the buffer immediately
instead of leaving it in a partially initialized pte.
Addresses: https://github.com/util-linux/util-linux/pull/4423
Signed-off-by: Karel Zak <kzak@redhat.com>
DBG(LABEL, ul_debug("DOS: reading EBR %zu: offset=%ju, buffer=%p",
pno, (uintmax_t) offset, buf));
DBG(LABEL, ul_debug("DOS: reading EBR %zu: offset=%ju, buffer=%p",
pno, (uintmax_t) offset, buf));
- pe->offset = offset;
- pe->sectorbuffer = buf;
- pe->private_sectorbuffer = 1;
-
- rc = read_sector(cxt, offset, pe->sectorbuffer);
+ rc = read_sector(cxt, offset, buf);
if (rc) {
fdisk_warn(cxt, _("Failed to read extended partition table "
"(offset=%ju)"), (uintmax_t) offset);
if (rc) {
fdisk_warn(cxt, _("Failed to read extended partition table "
"(offset=%ju)"), (uintmax_t) offset);
+ pe->offset = offset;
+ pe->sectorbuffer = buf;
+ pe->private_sectorbuffer = 1;
pe->changed = 0;
pe->pt_entry = pe->ex_entry = NULL;
return 0;
pe->changed = 0;
pe->pt_entry = pe->ex_entry = NULL;
return 0;