diff options
author | Karel Zak | 2016-04-25 11:59:06 +0200 |
---|---|---|
committer | Karel Zak | 2016-04-25 11:59:06 +0200 |
commit | b362a4cb986f7eea4b884c800719971502e2e8a8 (patch) | |
tree | 9b3fdf7bde4a1febbd8e0f83b31513e8871de1b2 /libfdisk | |
parent | libsmartcols remove duplicate code (diff) | |
download | kernel-qcow2-util-linux-b362a4cb986f7eea4b884c800719971502e2e8a8.tar.gz kernel-qcow2-util-linux-b362a4cb986f7eea4b884c800719971502e2e8a8.tar.xz kernel-qcow2-util-linux-b362a4cb986f7eea4b884c800719971502e2e8a8.zip |
libfdisk: don't offer zero length freespace
Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/table.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index 9be57139e..6d8cbc25a 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -394,6 +394,8 @@ static int new_freespace(struct fdisk_context *cxt, struct fdisk_partition *parent, struct fdisk_partition **pa) { + fdisk_sector_t aligned_start, size; + assert(cxt); assert(pa); @@ -401,17 +403,26 @@ static int new_freespace(struct fdisk_context *cxt, if (start == end) return 0; - *pa = fdisk_new_partition(); - if (!*pa) - return -ENOMEM; assert(start); assert(end); assert(end > start); + aligned_start = fdisk_align_lba_in_range(cxt, start, start, end); + size = end - aligned_start + 1ULL; + + if (size == 0) { + DBG(TAB, ul_debug("ignore freespace (aligned size is zero)")); + return 0; + } + + *pa = fdisk_new_partition(); + if (!*pa) + return -ENOMEM; + (*pa)->freespace = 1; - (*pa)->start = fdisk_align_lba_in_range(cxt, start, start, end); - (*pa)->size = end - (*pa)->start + 1ULL; + (*pa)->start = aligned_start; + (*pa)->size = size; if (parent) (*pa)->parent_partno = parent->partno; |