From nobody@FreeBSD.org  Fri Sep 30 17:24:25 2005
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8D4B616A41F
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Sep 2005 17:24:25 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4A07143D48
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Sep 2005 17:24:25 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id j8UHOPTv046464
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Sep 2005 17:24:25 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id j8UHOORH046392;
	Fri, 30 Sep 2005 17:24:24 GMT
	(envelope-from nobody)
Message-Id: <200509301724.j8UHOORH046392@www.freebsd.org>
Date: Fri, 30 Sep 2005 17:24:24 GMT
From: Alex Lyashkov <shadow@psoft.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: bsdlabel assing wrong fs type.
X-Send-Pr-Version: www-2.3

>Number:         86765
>Category:       bin
>Synopsis:       [patch] bsdlabel(8) assigning wrong fs type.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 30 17:30:15 GMT 2005
>Closed-Date:    Mon Sep 06 15:55:39 UTC 2010
>Last-Modified:  Mon Sep 06 15:55:39 UTC 2010
>Originator:     Alex Lyashkov
>Release:        RELENG_5
>Organization:
PSoft
>Environment:
>Description:
bsdlabel assing wrong fs type.
>How-To-Repeat:
1. create empty partition
2. run bsdlabel -w -e for create slice and set fs type to 4.4BSD
3. exit with save.
4. run bsdlabel again - look to fs type - it`s changed to SystemV.
5. exit with save. and look bsdlabel write error message about wring FS type.
6. run bsdlabel agen and see fs type assigned to unknow.

>Fix:
don`t know how fix it.
>Release-Note:
>Audit-Trail:

From: Jaakko Heinonen <jh@FreeBSD.org>
To: bug-followup@FreeBSD.org, shadow@psoft.net
Cc:  
Subject: Re: bin/86765: bsdlabel(8) assigning wrong fs type.
Date: Fri, 2 Jul 2010 19:23:18 +0300

 I can reproduce this. "4.4BSD" is not a valid file system type but
 bsdlabel(8) mishandles it because it doesn't check if strtoul(3)
 succeeds to convert the entire string in getasciipartspec((). Thus it
 considers "4.4BSD" as 4 which is the type number for "System V". Another
 bug is that bsdlabel(8) can't parse file system type names with spaces.
 There are four type names with a space defined in sys/disklabel.h.
 
 The patch below seems to fix the reported problem for me but there are
 more unchecked strtoul(3) calls which I didn't investigate. Also, it
 doesn't fix the problem with spaces in type names.
 
 %%%
 Index: sbin/bsdlabel/bsdlabel.c
 ===================================================================
 --- sbin/bsdlabel/bsdlabel.c	(revision 209622)
 +++ sbin/bsdlabel/bsdlabel.c	(working copy)
 @@ -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,7 +794,10 @@ 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);
 @@ -1023,7 +1026,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 +1062,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,
 %%%
 
 -- 
 Jaakko
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Jul 2 19:30:20 UTC 2010 
Responsible-Changed-Why:  
New patch submitted.  Although it applies to bin/, perhaps the folks on -fs 
could review it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86765 
Responsible-Changed-From-To: freebsd-fs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Mon Aug 9 17:27:20 UTC 2010 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86765 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/86765: commit references a PR
Date: Sun, 15 Aug 2010 17:49:55 +0000 (UTC)

 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,
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: jh 
State-Changed-When: Sun Aug 15 18:04:20 UTC 2010 
State-Changed-Why:  
Patched in head (r211342). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86765 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/86765: commit references a PR
Date: Mon, 30 Aug 2010 14:44:41 +0000 (UTC)

 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,
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/86765: commit references a PR
Date: Mon,  6 Sep 2010 15:48:20 +0000 (UTC)

 Author: jh
 Date: Mon Sep  6 15:48:06 2010
 New Revision: 212258
 URL: http://svn.freebsd.org/changeset/base/212258
 
 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/7/sbin/bsdlabel/bsdlabel.c
 Directory Properties:
   stable/7/sbin/bsdlabel/   (props changed)
 
 Modified: stable/7/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- stable/7/sbin/bsdlabel/bsdlabel.c	Mon Sep  6 13:47:11 2010	(r212257)
 +++ stable/7/sbin/bsdlabel/bsdlabel.c	Mon Sep  6 15:48:06 2010	(r212258)
 @@ -727,7 +727,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];
 @@ -766,11 +766,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")) {
 @@ -995,7 +999,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;
  
 @@ -1031,9 +1035,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,
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jh 
State-Changed-When: Mon Sep 6 15:55:38 UTC 2010 
State-Changed-Why:  
Fixed in head, stable/8 and stable/7. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=86765 
>Unformatted:
