Synopsis: disklabel 'b' suffix not working when adding partition with editor
Category:      i386
Environment:
        System      : OpenBSD 5.0
Details : OpenBSD 5.0 (GENERIC) #43: Wed Aug 17 10:10:52 MDT 2011 [email protected]:/usr/src/sys/arch/i386/compile/GENERIC

        Architecture: OpenBSD.i386
        Machine     : i386
Description:
Adding a new patition from the disklabel interactive editor, and specifying the partition size in bytes, by appending a 'b' suffix to the size, always leads to a error. The error message says:

"The size can't be more than 2048 sectors, or the partition would
        extend beyond the last sector (2048) of the OpenBSD portion of
        the disk. The 'b' command can change this limit."

Where 2048 is my test disk size. This even happens when requesting a partition of 1 byte big.
How-To-Repeat:
        # disklabel -E vnd0
        > d *
        > a a
        \n
        1b
Fix:
This issue is caused by trying to make a 32-bit unsigned integer negative, before storing it in a 64-bit signed integer. This leads to the value being ULONG_MAX-value, insteald of -value. The following patch fixes this issue, by first making the unsigned integer signed:
--- sbin/disklabel/editor.c.orig        Thu Dec  1 14:55:44 2011
+++ sbin/disklabel/editor.c     Thu Dec  1 16:33:16 2011
@@ -1178,12 +1178,12 @@ getuint(struct disklabel *lp, char *prompt, char *help
                                        buf[--n] = '\0';
                                        break;
                                case 'b':
-                                       mult = -lp->d_secsize;
+ mult = -((int64_t) lp->d_secsize);
                                        buf[--n] = '\0';
                                        break;
                                case 'k':
                                        if (lp->d_secsize > 1024)
- mult = -lp->d_secsize / 1024LL; + mult = -((int64_t) lp->d_secsize) / 1024LL;
                                        else
mult = 1024LL / lp->d_secsize;
                                        buf[--n] = '\0';

Reply via email to