diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2018-09-11 09:13:20 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2018-09-11 09:13:20 +0000 |
commit | 10d6c49040c01ca5139af2d17b05cdb90759fadb (patch) | |
tree | 6431dc5eea08d9e1617f6d7256277f01e959eb2a | |
parent | 6ff2783a80777cfc88d4986c614a9bc346ca4ba8 (diff) |
Tighten validation tests on an obscure corner case of
trying to align partitions to size <= 0 or past the
end of the disk. Emit error message in this case as
in other align errors.
Looks good to otto@.
-rw-r--r-- | sbin/disklabel/editor.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 060d80df44e..b669a1df40f 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.348 2018/08/30 13:07:19 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.349 2018/09/11 09:13:19 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -2505,25 +2505,34 @@ alignpartition(struct disklabel *lp, int partno, u_int64_t startalign, break; } if (chunks[i].stop == 0) { - fprintf(stderr, "offset %llu is outside the OpenBSD bounds " - "or inside another partition\n", start); + fprintf(stderr, "'%c' aligned offset %llu lies outside " + "the OpenBSD bounds or inside another partition\n", + 'a' + partno, start); return (1); } - maxstop = (chunks[i].stop / stopalign) * stopalign; /* Calculate the new 'stop' sector, the sector after the partition. */ + if ((flags & ROUND_SIZE_OVERLAP) == 0) + maxstop = (chunks[i].stop / stopalign) * stopalign; + else + maxstop = (ending_sector / stopalign) * stopalign; + stop = DL_GETPOFFSET(pp) + DL_GETPSIZE(pp); if ((flags & ROUND_SIZE_UP) == ROUND_SIZE_UP) stop = ((stop + stopalign - 1) / stopalign) * stopalign; else if ((flags & ROUND_SIZE_DOWN) == ROUND_SIZE_DOWN) stop = (stop / stopalign) * stopalign; - - if (((flags & ROUND_SIZE_OVERLAP) == 0) && stop > maxstop) + if (stop > maxstop) stop = maxstop; + if (stop <= start) { + fprintf(stderr, "'%c' aligned size <= 0\n", 'a' + partno); + return (1); + } + if (start != DL_GETPOFFSET(pp)) DL_SETPOFFSET(pp, start); - if (stop > start && stop != DL_GETPOFFSET(pp) + DL_GETPSIZE(pp)) + if (stop != DL_GETPOFFSET(pp) + DL_GETPSIZE(pp)) DL_SETPSIZE(pp, stop - start); return (0); |