On Fri, 15 Nov 2002, Nate Lawson wrote:

> On Sat, 16 Nov 2002, Tim Robbins wrote:
> > On Fri, Nov 15, 2002 at 03:59:25PM -0800, Julian Elischer wrote:
> > 
> > > Here are the diffs to allow disklabel to correctly create partitions >
> > > 1TB (up to 2TB is useful with UFS2) pending a different partitionning
> > > scheme. It also allows you to correctly make smaller partitions beyond
> > > 1TB which is nice if you don't want to waste 800GB on an array :-)
> > > 
> > > 
> > > permission to commit please?
> > > (pending comments by others)
> > > 
> > > (also the sysinstall changes posted before)
> > > (also the bluetooth code)
> > [...]
> > > -                 v = atoi(tp);
> > > +                 v = strtoul(tp, NULL, 0);
> > >                   if (v <= 0 || (v % DEV_BSIZE) != 0) {
> > >                           fprintf(stderr,
> > >                               "line %d: %s: bad sector size\n",
> > 
> > Should be == 0, not <= 0 since v is unsigned.
good catch.
I've altered all the checks of v to be unsigned..


> > 
> > [...]
> > > -                 v = atoi(tp);
> > > +                 v = strtoul(tp, NULL, 0);
> > >                   if (v < 0) {
> > >                           fprintf(stderr, "line %d: %s: bad %s\n",
> > >                               lineno, tp, cp);
> > 
> > v < 0 is impossible.
> 
> In the overflow case, strtoul returns ULONG_MAX.  Or if you're interested
> in catching invalid characters, use endptr.

I'm not that interested in catching those cases.. they were not caught
before and I'm looking for the minimal diff..

I've just removed the clause. See new patch attached..
A sensible thing might be to compare against a "sensible" value
but who knows what that value should be?

I include the new diff for your coments

Any comments from anyone about the sysinstall fixes would also be
apreciated..


> 
> -Nate
> 
> 
> To Unsubscribe: send mail to [EMAIL PROTECTED]
> with "unsubscribe freebsd-current" in the body of the message
> 
Index: disklabel.c
===================================================================
RCS file: /home/ncvs/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.62
diff -u -r1.62 disklabel.c
--- disklabel.c 8 Oct 2002 12:13:19 -0000       1.62
+++ disklabel.c 16 Nov 2002 08:23:14 -0000
@@ -943,7 +943,8 @@
        const char **cpp;
        unsigned int part;
        char *tp, line[BUFSIZ];
-       int v, lineno = 0, errors = 0;
+       unsigned int v;
+       int lineno = 0, errors = 0;
        int i;
 
        lp->d_bbsize = BBSIZE;                          /* XXX */
@@ -973,7 +974,7 @@
                                }
                        if (cpp < &dktypenames[DKMAXTYPES])
                                continue;
-                       v = atoi(tp);
+                       v = strtoul(tp, NULL, 0);
                        if ((unsigned)v >= DKMAXTYPES)
                                fprintf(stderr, "line %d:%s %d\n", lineno,
                                    "Warning, unknown disk type", v);
@@ -1006,8 +1007,8 @@
                        }
                        continue;
                }
-               if (sscanf(cp, "%d partitions", &v) == 1) {
-                       if (v == 0 || (unsigned)v > MAXPARTITIONS) {
+               if (sscanf(cp, "%u partitions", &v) == 1) {
+                       if (v == 0 || v > MAXPARTITIONS) {
                                fprintf(stderr,
                                    "line %d: bad # of partitions\n", lineno);
                                lp->d_npartitions = MAXPARTITIONS;
@@ -1027,8 +1028,8 @@
                        continue;
                }
                if (streq(cp, "bytes/sector")) {
-                       v = atoi(tp);
-                       if (v <= 0 || (v % DEV_BSIZE) != 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0 || (v % DEV_BSIZE) != 0) {
                                fprintf(stderr,
                                    "line %d: %s: bad sector size\n",
                                    lineno, tp);
@@ -1038,8 +1039,8 @@
                        continue;
                }
                if (streq(cp, "sectors/track")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1048,8 +1049,8 @@
                        continue;
                }
                if (streq(cp, "sectors/cylinder")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1058,8 +1059,8 @@
                        continue;
                }
                if (streq(cp, "tracks/cylinder")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1068,8 +1069,8 @@
                        continue;
                }
                if (streq(cp, "cylinders")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1078,8 +1079,8 @@
                        continue;
                }
                if (streq(cp, "sectors/unit")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1088,8 +1089,8 @@
                        continue;
                }
                if (streq(cp, "rpm")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1098,8 +1099,8 @@
                        continue;
                }
                if (streq(cp, "interleave")) {
-                       v = atoi(tp);
-                       if (v <= 0) {
+                       v = strtoul(tp, NULL, 0);
+                       if (v == 0) {
                                fprintf(stderr, "line %d: %s: bad %s\n",
                                    lineno, tp, cp);
                                errors++;
@@ -1108,43 +1109,23 @@
                        continue;
                }
                if (streq(cp, "trackskew")) {
-                       v = atoi(tp);
-                       if (v < 0) {
-                               fprintf(stderr, "line %d: %s: bad %s\n",
-                                   lineno, tp, cp);
-                               errors++;
-                       } else
-                               lp->d_trackskew = v;
+                       v = strtoul(tp, NULL, 0);
+                       lp->d_trackskew = v;
                        continue;
                }
                if (streq(cp, "cylinderskew")) {
-                       v = atoi(tp);
-                       if (v < 0) {
-                               fprintf(stderr, "line %d: %s: bad %s\n",
-                                   lineno, tp, cp);
-                               errors++;
-                       } else
-                               lp->d_cylskew = v;
+                       v = strtoul(tp, NULL, 0);
+                       lp->d_cylskew = v;
                        continue;
                }
                if (streq(cp, "headswitch")) {
-                       v = atoi(tp);
-                       if (v < 0) {
-                               fprintf(stderr, "line %d: %s: bad %s\n",
-                                   lineno, tp, cp);
-                               errors++;
-                       } else
-                               lp->d_headswitch = v;
+                       v = strtoul(tp, NULL, 0);
+                       lp->d_headswitch = v;
                        continue;
                }
                if (streq(cp, "track-to-track seek")) {
-                       v = atoi(tp);
-                       if (v < 0) {
-                               fprintf(stderr, "line %d: %s: bad %s\n",
-                                   lineno, tp, cp);
-                               errors++;
-                       } else
-                               lp->d_trkseek = v;
+                       v = strtoul(tp, NULL, 0);
+                       lp->d_trkseek = v;
                        continue;
                }
                /* the ':' was removed above */
@@ -1182,7 +1163,7 @@
                return (1); \
        } else { \
                cp = tp, tp = word(cp); \
-               (n) = atoi(cp); \
+               (n) = strtoul(cp, NULL, 0); \
        } \
 } while (0)
 
@@ -1194,7 +1175,7 @@
        } else { \
                char *tmp; \
                cp = tp, tp = word(cp); \
-               (n) = strtol(cp,&tmp,10); \
+               (n) = strtoul(cp, &tmp, 10); \
                if (tmp) (w) = *tmp; \
        } \
 } while (0)
@@ -1209,14 +1190,14 @@
        struct partition *pp;
        char *cp;
        const char **cpp;
-       int v;
+       unsigned int v;
 
        pp = &lp->d_partitions[part];
        cp = NULL;
 
        v = 0;
        NXTWORD(part_size_type[part],v);
-       if (v < 0 || (v == 0 && part_size_type[part] != '*')) {
+       if (v == 0 && part_size_type[part] != '*') {
                fprintf(stderr, "line %d: %s: bad partition size\n", lineno,
                    cp);
                return (1);
@@ -1225,8 +1206,8 @@
 
        v = 0;
        NXTWORD(part_offset_type[part],v);
-       if (v < 0 || (v == 0 && part_offset_type[part] != '*' &&
-           part_offset_type[part] != '\0')) {
+       if (v == 0 && part_offset_type[part] != '*' &&
+           part_offset_type[part] != '\0') {
                fprintf(stderr, "line %d: %s: bad partition offset\n", lineno,
                    cp);
                return (1);
@@ -1240,7 +1221,7 @@
                pp->p_fstype = cpp - fstypenames;
        } else {
                if (isdigit(*cp))
-                       v = atoi(cp);
+                       v = strtoul(cp, NULL, 0);
                else
                        v = FSMAXTYPES;
                if ((unsigned)v >= FSMAXTYPES) {

Reply via email to