svn commit: r211342 - head/sbin/bsdlabel

Jaakko Heinonen jh at FreeBSD.org
Sun Aug 15 17:49:42 UTC 2010


Author: jh
Date: Sun Aug 15 17:49:41 2010
New Revision: 211342
URL: http://svn.freebsd.org/changeset/base/211342

Log:
  - 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
  MFC after:	2 weeks

Modified:
  head/sbin/bsdlabel/bsdlabel.c

Modified: head/sbin/bsdlabel/bsdlabel.c
==============================================================================
--- head/sbin/bsdlabel/bsdlabel.c	Sun Aug 15 17:14:05 2010	(r211341)
+++ head/sbin/bsdlabel/bsdlabel.c	Sun Aug 15 17:49:41 2010	(r211342)
@@ -755,7 +755,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];
@@ -794,11 +794,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")) {
@@ -1023,7 +1027,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;
 
@@ -1059,9 +1063,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,


More information about the svn-src-head mailing list