From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: util-linux@vger.kernel.org
Subject: [PATCH 1/2] Fix assert error in libfdisk's free space handling
Date: Sat, 27 Aug 2016 19:28:16 +0200 [thread overview]
Message-ID: <20160827172816.GA11886@localhost> (raw)
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 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 755c6c2..bf30d1b 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -616,7 +616,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
/* We ignore small free spaces (smaller than grain) to keep partitions
* aligned, the exception is space before the first partition where
* we assume that cxt->first_lba is aligned. */
- if (last + grain <= pa->start
+ if (last + grain < pa->start
|| (last < pa->start && last == cxt->first_lba)) {
rc = table_add_freespace(cxt, *tb,
last + (last > cxt->first_lba ? 1 : 0),
--
2.9.3
next reply other threads:[~2016-08-27 17:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-27 17:28 Tobias Stoeckmann [this message]
2016-08-29 11:35 ` [PATCH 1/2] Fix assert error in libfdisk's free space handling Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160827172816.GA11886@localhost \
--to=tobias@stoeckmann.org \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.