]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libfdisk: Fix assert error in free space handling
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 27 Aug 2016 17:28:16 +0000 (19:28 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 29 Aug 2016 11:22:24 +0000 (13:22 +0200)
commit848018183869d908ddfa59ce7362272f65baa860
tree710c9f000c3ca3570bdacc80c41a1aaf3a5cc782
parente132ae59cae70f5500e39d995ae6fdee044ffeee
libfdisk: Fix assert error in free space handling

An off-by-one issue exists in fdisk_get_freespaces. It can trigger an
assert, as seen here:

$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,2' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Aborted
$ _

Problem here is an invalid "grain" processing. A grain is considered
expected free space between partitions which can be required for proper
alignment. Normally, it's 1 MB but in this case our iso is merely 1 MB
so the grain is reduced to 1 byte.

The if-condition in question checks for "last + grain <= pa->start" and
therefore even triggers if there is no space between them (due to equal
check). Eventually, the start block address is higher than the end block
address which triggers the assert().

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
libfdisk/src/table.c