fdisk(1) uses a signed int for slice sizes

Mark Johnston markjdb at gmail.com
Tue May 24 16:08:51 UTC 2011


Hello all,

fdisk(1) uses a signed int to store slice sizes when reading in a config
file. On platforms with sizeof(int) == 4, this prevents users from
specifying a size of more than 2^{31}-1 sectors even though the
corresponding MBR field is a 32-bit unsigned number.

I have a little patch which fixes this; I was going to ask rstone@ to
commit it, but I'd like to know if there are any objections/comments first.

Thanks,
-Mark

diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index 8314906..eb81e3b 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -108,9 +108,9 @@ typedef struct cmd {
     char		cmd;
     int			n_args;
     struct arg {
-	char	argtype;
-	int	arg_val;
-	char	*arg_str;
+	char		argtype;
+	unsigned long	arg_val;
+	char *		arg_str;
     }			args[MAX_ARGS];
 } CMD;
 
@@ -990,7 +990,7 @@ parse_config_line(char *line, CMD *command)
 	    if (isalpha(*cp))
 		command->args[command->n_args].argtype = *cp++;
 	    end = NULL;
-	    command->args[command->n_args].arg_val = strtol(cp, &end, 0);
+	    command->args[command->n_args].arg_val = strtoul(cp, &end, 0);
  	    if (cp == end || (!isspace(*end) && *end != '\0')) {
  		char ch;
  		end = cp;


More information about the freebsd-fs mailing list