Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Aug 2010 14:44:22 +0000 (UTC)
From:      Jaakko Heinonen <jh@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r212000 - stable/8/sbin/bsdlabel
Message-ID:  <201008301444.o7UEiM46097893@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jh
Date: Mon Aug 30 14:44:22 2010
New Revision: 212000
URL: http://svn.freebsd.org/changeset/base/212000

Log:
  MFC r211342:
  
  - Check that strtoul(3) succeeds to convert the entire string in a few
    places.
  - In getasciilabel(), set the disk type only when a valid type is given.
  
  PR:		bin/86765

Modified:
  stable/8/sbin/bsdlabel/bsdlabel.c
Directory Properties:
  stable/8/sbin/bsdlabel/   (props changed)

Modified: stable/8/sbin/bsdlabel/bsdlabel.c
==============================================================================
--- stable/8/sbin/bsdlabel/bsdlabel.c	Mon Aug 30 14:26:02 2010	(r211999)
+++ stable/8/sbin/bsdlabel/bsdlabel.c	Mon Aug 30 14:44:22 2010	(r212000)
@@ -749,7 +749,7 @@ word(char *cp)
 static int
 getasciilabel(FILE *f, struct disklabel *lp)
 {
-	char *cp;
+	char *cp, *endp;
 	const char **cpp;
 	u_int part;
 	char *tp, line[BUFSIZ];
@@ -788,11 +788,15 @@ getasciilabel(FILE *f, struct disklabel 
 				}
 			if (cpp < &dktypenames[DKMAXTYPES])
 				continue;
-			v = strtoul(tp, NULL, 10);
+			errno = 0;
+			v = strtoul(tp, &endp, 10);
+			if (errno != 0 || *endp != '\0')
+				v = DKMAXTYPES;
 			if (v >= DKMAXTYPES)
 				fprintf(stderr, "line %d:%s %lu\n", lineno,
 				    "Warning, unknown disk type", v);
-			lp->d_type = v;
+			else
+				lp->d_type = v;
 			continue;
 		}
 		if (!strcmp(cp, "flags")) {
@@ -1017,7 +1021,7 @@ static int
 getasciipartspec(char *tp, struct disklabel *lp, int part, int lineno)
 {
 	struct partition *pp;
-	char *cp;
+	char *cp, *endp;
 	const char **cpp;
 	u_long v;
 
@@ -1053,9 +1057,12 @@ getasciipartspec(char *tp, struct diskla
 	if (*cpp != NULL) {
 		pp->p_fstype = cpp - fstypenames;
 	} else {
-		if (isdigit(*cp))
-			v = strtoul(cp, NULL, 10);
-		else
+		if (isdigit(*cp)) {
+			errno = 0;
+			v = strtoul(cp, &endp, 10);
+			if (errno != 0 || *endp != '\0')
+				v = FSMAXTYPES;
+		} else
 			v = FSMAXTYPES;
 		if (v >= FSMAXTYPES) {
 			fprintf(stderr,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201008301444.o7UEiM46097893>