From nobody@FreeBSD.org  Fri Feb 26 01:16:02 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 70500106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 26 Feb 2010 01:16:02 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 0ED698FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 26 Feb 2010 01:16:02 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o1Q1G1bS096819
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 26 Feb 2010 01:16:01 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o1Q1G1mu096818;
	Fri, 26 Feb 2010 01:16:01 GMT
	(envelope-from nobody)
Message-Id: <201002260116.o1Q1G1mu096818@www.freebsd.org>
Date: Fri, 26 Feb 2010 01:16:01 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ENOENT set unnecessarily under certain circumstances when malloc is called / fails
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         144307
>Category:       kern
>Synopsis:       [libc] [patch] ENOENT set unnecessarily under certain circumstances when malloc is called / fails
>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 Feb 26 01:20:01 UTC 2010
>Closed-Date:    Wed Aug 18 15:00:37 UTC 2010
>Last-Modified:  Sun Feb 03 22:28:05 UTC 2013
>Originator:     Garrett Cooper
>Release:        RELENG_8
>Organization:
Cisco Systems, Inc
>Environment:
FreeBSD garrcoop-fbsd.cisco.com 8.0-STABLE FreeBSD 8.0-STABLE #2: Wed Feb  3 16:57:07 PST 2010     garrcoop@garrcoop-fbsd.cisco.com:/usr/obj/usr/src/sys/LAPPY_X86  i386
>Description:
On systems where /etc/malloc.conf isn't present, some failures syscalls like read will fail incorrectly with ENOENT because the file doesn't exist, and thus output via errx will be incorrect, like shown from the following disklabel output:

1+0 records in
1+0 records out
512 bytes transferred in 0.000054 secs (9502140 bytes/sec)
disklabel: /dev/md1 read: No such file or directory

This can be reproduced as follows (yes, the dd command are stat commands are wrong -- I know that...) if malloc.conf is not present:

dd if=/dev/zero of=$output_file conv=sparse bs=$(stat -f '%z' "$input_directory") count=1
mdconfig -a -t vnode -u ${md_num} -f "$output_file"
disklabel -rw /dev/md${md_num} auto

Once malloc.conf is present...

sudo ln -s M /etc/malloc.conf

# ...

1+0 records in
1+0 records out
512 bytes transferred in 0.000054 secs (9460280 bytes/sec)
disklabel: /dev/md1 read: Unknown error: 0
>How-To-Repeat:
dd if=/dev/zero of=foo conv=sparse bs=512 count=1
mdconfig -a -t vnode -u 1 -f foo
disklabel -rw /dev/md1 auto
>Fix:
1. Set malloc.conf to a valid value as per malloc(3).
2. Apply attached patch.

Patch attached with submission follows:

Index: lib/libc/stdlib/malloc.c
===================================================================
--- lib/libc/stdlib/malloc.c	(revision 204027)
+++ lib/libc/stdlib/malloc.c	(working copy)
@@ -5408,6 +5408,11 @@
 		/* Get runtime configuration. */
 		switch (i) {
 		case 0:
+			/* 
+			 * Make sure that a valid errno code doesn't get wiped
+			 * out if malloc.conf doesn't exist.
+			 */
+			int saved_errno = errno;
 			if ((linklen = readlink("/etc/malloc.conf", buf,
 						sizeof(buf) - 1)) != -1) {
 				/*
@@ -5421,6 +5426,7 @@
 				buf[0] = '\0';
 				opts = buf;
 			}
+			errno = saved_errno;
 			break;
 		case 1:
 			if (issetugid() == 0 && (opts =


>Release-Note:
>Audit-Trail:

From: Jaakko Heinonen <jh@FreeBSD.org>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: bug-followup@FreeBSD.org
Subject: Re: kern/144307: ENOENT set unnecessarily under certain
 circumstances when malloc is called / fails
Date: Mon, 28 Jun 2010 22:05:40 +0300

 On 2010-02-26, Garrett Cooper wrote:
 > On systems where /etc/malloc.conf isn't present, some failures
 > syscalls like read will fail incorrectly with ENOENT because the file
 > doesn't exist, and thus output via errx will be incorrect, like shown
 
 I think you mean err(3), not errx(3).
 
 > from the following disklabel output:
 > 
 > 1+0 records in
 > 1+0 records out
 > 512 bytes transferred in 0.000054 secs (9502140 bytes/sec)
 > disklabel: /dev/md1 read: No such file or directory
 
 It's a disklabel bug to inspect the errno value in the success case.
 POSIX states: "The value of errno should only be examined when it is
 indicated to be valid by a function's return value." and "The setting of
 errno after a successful call to a function is unspecified unless the
 description of that function specifies that errno shall not be
 modified.".
 
 This patch for bsdlabel(8) might fix the error message:
 
 %%%
 Index: sbin/bsdlabel/bsdlabel.c
 ===================================================================
 --- sbin/bsdlabel/bsdlabel.c	(revision 209580)
 +++ sbin/bsdlabel/bsdlabel.c	(working copy)
 @@ -312,7 +312,7 @@ static void
  fixlabel(struct disklabel *lp)
  {
  	struct partition *dp;
 -	int i;
 +	ssize_t i;
  
  	for (i = 0; i < lp->d_npartitions; i++) {
  		if (i == RAW_PART)
 @@ -359,8 +359,11 @@ readboot(void)
  	fstat(fd, &st);
  	if (alphacksum && st.st_size <= BBSIZE - 512) {
  		i = read(fd, bootarea + 512, st.st_size);
 -		if (i != st.st_size)
 +		if (i == -1)
  			err(1, "read error %s", xxboot);
 +		if (i != st.st_size)
 +			errx(1, "couldn't read %ju bytes from %s",
 +			    (uintmax_t)st.st_size, xxboot);
  
  		/*
  		 * Set the location and length so SRM can find the
 @@ -373,8 +376,11 @@ readboot(void)
  		return;
  	} else if ((!alphacksum) && st.st_size <= BBSIZE) {
  		i = read(fd, bootarea, st.st_size);
 -		if (i != st.st_size)
 +		if (i == -1)
  			err(1, "read error %s", xxboot);
 +		if (i != st.st_size)
 +			errx(1, "couldn't read %ju bytes from %s",
 +			    (uintmax_t)st.st_size, xxboot);
  		return;
  	}
  	errx(1, "boot code %s is wrong size", xxboot);
 @@ -499,7 +505,7 @@ readlabel(int flag)
  		    "disks with more than 2^32-1 sectors are not supported");
  	(void)lseek(f, (off_t)0, SEEK_SET);
  	if (read(f, bootarea, BBSIZE) != BBSIZE)
 -		err(4, "%s read", specname);
 +		errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
  	close (f);
  	error = bsd_disklabel_le_dec(
  	    bootarea + (labeloffset + labelsoffset * secsize),
 %%%
 
 -- 
 Jaakko

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Jaakko Heinonen <jh@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: kern/144307: ENOENT set unnecessarily under certain circumstances 
	when malloc is called / fails
Date: Mon, 28 Jun 2010 12:46:17 -0700

 On Mon, Jun 28, 2010 at 12:05 PM, Jaakko Heinonen <jh@freebsd.org> wrote:
 > On 2010-02-26, Garrett Cooper wrote:
 >> On systems where /etc/malloc.conf isn't present, some failures
 >> syscalls like read will fail incorrectly with ENOENT because the file
 >> doesn't exist, and thus output via errx will be incorrect, like shown
 >
 > I think you mean err(3), not errx(3).
 
 Yeah... true :).
 
 >> from the following disklabel output:
 >>
 >> 1+0 records in
 >> 1+0 records out
 >> 512 bytes transferred in 0.000054 secs (9502140 bytes/sec)
 >> disklabel: /dev/md1 read: No such file or directory
 >
 > It's a disklabel bug to inspect the errno value in the success case.
 > POSIX states: "The value of errno should only be examined when it is
 > indicated to be valid by a function's return value." and "The setting of
 > errno after a successful call to a function is unspecified unless the
 > description of that function specifies that errno shall not be
 > modified.".
 >
 > This patch for bsdlabel(8) might fix the error message:
 >
 > %%%
 > Index: sbin/bsdlabel/bsdlabel.c
 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 > --- sbin/bsdlabel/bsdlabel.c =A0 =A0(revision 209580)
 > +++ sbin/bsdlabel/bsdlabel.c =A0 =A0(working copy)
 > @@ -312,7 +312,7 @@ static void
 > =A0fixlabel(struct disklabel *lp)
 > =A0{
 > =A0 =A0 =A0 =A0struct partition *dp;
 > - =A0 =A0 =A0 int i;
 > + =A0 =A0 =A0 ssize_t i;
 
      Good catch on the implicit cast.
 
 > =A0 =A0 =A0 =A0for (i =3D 0; i < lp->d_npartitions; i++) {
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (i =3D=3D RAW_PART)
 > @@ -359,8 +359,11 @@ readboot(void)
 > =A0 =A0 =A0 =A0fstat(fd, &st);
 > =A0 =A0 =A0 =A0if (alphacksum && st.st_size <=3D BBSIZE - 512) {
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i =3D read(fd, bootarea + 512, st.st_size)=
 ;
 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i !=3D st.st_size)
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D -1)
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err(1, "read error %s", xx=
 boot);
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i !=3D st.st_size)
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 errx(1, "couldn't read %ju =
 bytes from %s",
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (uintmax_t)st.st_si=
 ze, xxboot);
 >
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/*
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * Set the location and length so SRM can =
 find the
 > @@ -373,8 +376,11 @@ readboot(void)
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return;
 > =A0 =A0 =A0 =A0} else if ((!alphacksum) && st.st_size <=3D BBSIZE) {
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0i =3D read(fd, bootarea, st.st_size);
 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i !=3D st.st_size)
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D -1)
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err(1, "read error %s", xx=
 boot);
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (i !=3D st.st_size)
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 errx(1, "couldn't read %ju =
 bytes from %s",
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (uintmax_t)st.st_si=
 ze, xxboot);
 
     Or the malloc(3) call could be fixed with the couple of lines I
 noted (well, adlibbed of course... I wrote the patch before I started
 familiarizing myself with style(9))?
 
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return;
 > =A0 =A0 =A0 =A0}
 > =A0 =A0 =A0 =A0errx(1, "boot code %s is wrong size", xxboot);
 > @@ -499,7 +505,7 @@ readlabel(int flag)
 > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"disks with more than 2^32-1 secto=
 rs are not supported");
 > =A0 =A0 =A0 =A0(void)lseek(f, (off_t)0, SEEK_SET);
 > =A0 =A0 =A0 =A0if (read(f, bootarea, BBSIZE) !=3D BBSIZE)
 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 err(4, "%s read", specname);
 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 errx(4, "couldn't read %d bytes from %s", B=
 BSIZE, specname);
 > =A0 =A0 =A0 =A0close (f);
 > =A0 =A0 =A0 =A0error =3D bsd_disklabel_le_dec(
 > =A0 =A0 =A0 =A0 =A0 =A0bootarea + (labeloffset + labelsoffset * secsize),
 > %%%
 
     Which I agree with, but shouldn't we fix malloc(3) (and any other
 function calls that depend on malloc(3) for sensible results)?
 Thanks!
 -Garrett
 
 PS Neither malloc nor read mentions ENOENT in their respective
 manpages (and if they did it would be non-POSIX compliant -
 http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html ,
 http://opengroup.org/onlinepubs/007908775/xsh/read.html).

From: Jaakko Heinonen <jh@FreeBSD.org>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/144307: ENOENT set unnecessarily under certain
 circumstances when malloc is called / fails
Date: Mon, 28 Jun 2010 23:10:11 +0300

 On 2010-06-28, Garrett Cooper wrote:
 >     Or the malloc(3) call could be fixed with the couple of lines I
 > noted (well, adlibbed of course...
 > 
 >     Which I agree with, but shouldn't we fix malloc(3) (and any other
 > function calls that depend on malloc(3) for sensible results)?
 
 It's not required for POSIX compliance at least. Did you actually read
 the quotes from POSIX?
 
 "The value of errno should only be examined when it is indicated to be
 valid by a function's return value."
 
 "The setting of errno after a successful call to a function is
 unspecified unless the description of that function specifies that errno
 shall not be modified."
 
 In other words the value of errno is undefined and shouldn't be
 examined unless malloc(3) returns NULL.
 
 -- 
 Jaakko

From: Garrett Cooper <yaneurabeya@gmail.com>
To: Jaakko Heinonen <jh@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: kern/144307: ENOENT set unnecessarily under certain circumstances 
	when malloc is called / fails
Date: Mon, 28 Jun 2010 15:17:32 -0700

 On Mon, Jun 28, 2010 at 1:10 PM, Jaakko Heinonen <jh@freebsd.org> wrote:
 > On 2010-06-28, Garrett Cooper wrote:
 >> =A0 =A0 Or the malloc(3) call could be fixed with the couple of lines I
 >> noted (well, adlibbed of course...
 >>
 >> =A0 =A0 Which I agree with, but shouldn't we fix malloc(3) (and any othe=
 r
 >> function calls that depend on malloc(3) for sensible results)?
 >
 > It's not required for POSIX compliance at least. Did you actually read
 > the quotes from POSIX?
 >
 > "The value of errno should only be examined when it is indicated to be
 > valid by a function's return value."
 >
 > "The setting of errno after a successful call to a function is
 > unspecified unless the description of that function specifies that errno
 > shall not be modified."
 >
 > In other words the value of errno is undefined and shouldn't be
 > examined unless malloc(3) returns NULL.
 
     Ok. The bsdlabel(8) item is valid, but in the meantime I'll write
 some testcases for read(2) to see whether or not I can find the
 recreate the failing condition when =3D=3D -1. Worst case we'll have more
 testcases to put in the tree...
 Thanks!
 -Garrett
Responsible-Changed-From-To: freebsd-bugs->jh 
Responsible-Changed-By: jh 
Responsible-Changed-When: Wed Jun 30 18:10:48 UTC 2010 
Responsible-Changed-Why:  
Take. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/144307: commit references a PR
Date: Wed, 30 Jun 2010 18:35:00 +0000 (UTC)

 Author: jh
 Date: Wed Jun 30 18:34:45 2010
 New Revision: 209614
 URL: http://svn.freebsd.org/changeset/base/209614
 
 Log:
   - Don't assign the return value from read(2) to a variable of type
     int.
   - Use errx(3) instead of err(3) to print the error message on short
     reads in readlabel(). errno won't be set on short reads which can
     easily occur here due to the fixed size read request.
   
   PR:		144307
   Reviewed by:	bde
 
 Modified:
   head/sbin/bsdlabel/bsdlabel.c
 
 Modified: head/sbin/bsdlabel/bsdlabel.c
 ==============================================================================
 --- head/sbin/bsdlabel/bsdlabel.c	Wed Jun 30 18:03:42 2010	(r209613)
 +++ head/sbin/bsdlabel/bsdlabel.c	Wed Jun 30 18:34:45 2010	(r209614)
 @@ -347,7 +347,7 @@ makelabel(const char *type, struct diskl
  static void
  readboot(void)
  {
 -	int fd, i;
 +	int fd;
  	struct stat st;
  	uint64_t *p;
  
 @@ -358,8 +358,7 @@ readboot(void)
  		err(1, "cannot open %s", xxboot);
  	fstat(fd, &st);
  	if (alphacksum && st.st_size <= BBSIZE - 512) {
 -		i = read(fd, bootarea + 512, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea + 512, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  
  		/*
 @@ -372,8 +371,7 @@ readboot(void)
  		p[62] = 0;
  		return;
  	} else if ((!alphacksum) && st.st_size <= BBSIZE) {
 -		i = read(fd, bootarea, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  		return;
  	}
 @@ -479,6 +477,7 @@ get_file_parms(int f)
  static int
  readlabel(int flag)
  {
 +	ssize_t nbytes;
  	uint32_t lba;
  	int f, i;
  	int error;
 @@ -498,8 +497,11 @@ readlabel(int flag)
  		errx(1,
  		    "disks with more than 2^32-1 sectors are not supported");
  	(void)lseek(f, (off_t)0, SEEK_SET);
 -	if (read(f, bootarea, BBSIZE) != BBSIZE)
 +	nbytes = read(f, bootarea, BBSIZE);
 +	if (nbytes == -1)
  		err(4, "%s read", specname);
 +	if (nbytes != BBSIZE)
 +		errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
  	close (f);
  	error = bsd_disklabel_le_dec(
  	    bootarea + (labeloffset + labelsoffset * secsize),
 _______________________________________________
 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: Wed Jun 30 18:53:31 UTC 2010 
State-Changed-Why:  
bsdlabel(8) patched in head (r209614). 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/144307: commit references a PR
Date: Mon,  2 Aug 2010 09:03:45 +0000 (UTC)

 Author: jh
 Date: Mon Aug  2 09:03:31 2010
 New Revision: 210744
 URL: http://svn.freebsd.org/changeset/base/210744
 
 Log:
   MFC r209614:
   
   - Don't assign the return value from read(2) to a variable of type
     int.
   - Use errx(3) instead of err(3) to print the error message on short
     reads in readlabel(). errno won't be set on short reads which can
     easily occur here due to the fixed size read request.
   
   PR:		144307
 
 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  2 08:35:16 2010	(r210743)
 +++ stable/8/sbin/bsdlabel/bsdlabel.c	Mon Aug  2 09:03:31 2010	(r210744)
 @@ -347,7 +347,7 @@ makelabel(const char *type, struct diskl
  static void
  readboot(void)
  {
 -	int fd, i;
 +	int fd;
  	struct stat st;
  	uint64_t *p;
  
 @@ -358,8 +358,7 @@ readboot(void)
  		err(1, "cannot open %s", xxboot);
  	fstat(fd, &st);
  	if (alphacksum && st.st_size <= BBSIZE - 512) {
 -		i = read(fd, bootarea + 512, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea + 512, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  
  		/*
 @@ -372,8 +371,7 @@ readboot(void)
  		p[62] = 0;
  		return;
  	} else if ((!alphacksum) && st.st_size <= BBSIZE) {
 -		i = read(fd, bootarea, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  		return;
  	}
 @@ -479,6 +477,7 @@ get_file_parms(int f)
  static int
  readlabel(int flag)
  {
 +	ssize_t nbytes;
  	uint32_t lba;
  	int f, i;
  	int error;
 @@ -498,8 +497,11 @@ readlabel(int flag)
  		errx(1,
  		    "disks with more than 2^32-1 sectors are not supported");
  	(void)lseek(f, (off_t)0, SEEK_SET);
 -	if (read(f, bootarea, BBSIZE) != BBSIZE)
 +	nbytes = read(f, bootarea, BBSIZE);
 +	if (nbytes == -1)
  		err(4, "%s read", specname);
 +	if (nbytes != BBSIZE)
 +		errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
  	close (f);
  	error = bsd_disklabel_le_dec(
  	    bootarea + (labeloffset + labelsoffset * secsize),
 _______________________________________________
 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: kern/144307: commit references a PR
Date: Wed, 18 Aug 2010 14:41:44 +0000 (UTC)

 Author: jh
 Date: Wed Aug 18 14:41:34 2010
 New Revision: 211454
 URL: http://svn.freebsd.org/changeset/base/211454
 
 Log:
   MFC r209614:
   
   - Don't assign the return value from read(2) to a variable of type
     int.
   - Use errx(3) instead of err(3) to print the error message on short
     reads in readlabel(). errno won't be set on short reads which can
     easily occur here due to the fixed size read request.
   
   PR:		144307
 
 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	Wed Aug 18 12:52:21 2010	(r211453)
 +++ stable/7/sbin/bsdlabel/bsdlabel.c	Wed Aug 18 14:41:34 2010	(r211454)
 @@ -334,7 +334,7 @@ makelabel(const char *type, struct diskl
  static void
  readboot(void)
  {
 -	int fd, i;
 +	int fd;
  	struct stat st;
  	uint64_t *p;
  
 @@ -345,8 +345,7 @@ readboot(void)
  		err(1, "cannot open %s", xxboot);
  	fstat(fd, &st);
  	if (alphacksum && st.st_size <= BBSIZE - 512) {
 -		i = read(fd, bootarea + 512, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea + 512, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  
  		/*
 @@ -359,8 +358,7 @@ readboot(void)
  		p[62] = 0;
  		return;
  	} else if ((!alphacksum) && st.st_size <= BBSIZE) {
 -		i = read(fd, bootarea, st.st_size);
 -		if (i != st.st_size)
 +		if (read(fd, bootarea, st.st_size) != st.st_size)
  			err(1, "read error %s", xxboot);
  		return;
  	}
 @@ -466,6 +464,7 @@ get_file_parms(int f)
  static int
  readlabel(int flag)
  {
 +	ssize_t nbytes;
  	int f, i;
  	int error;
  	struct gctl_req *grq;
 @@ -484,8 +483,11 @@ readlabel(int flag)
  		errx(1,
  		    "disks with more than 2^32-1 sectors are not supported");
  	(void)lseek(f, (off_t)0, SEEK_SET);
 -	if (read(f, bootarea, BBSIZE) != BBSIZE)
 +	nbytes = read(f, bootarea, BBSIZE);
 +	if (nbytes == -1)
  		err(4, "%s read", specname);
 +	if (nbytes != BBSIZE)
 +		errx(4, "couldn't read %d bytes from %s", BBSIZE, specname);
  	close (f);
  	error = bsd_disklabel_le_dec(
  	    bootarea + (labeloffset + labelsoffset * secsize),
 _______________________________________________
 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: Wed Aug 18 14:55:49 UTC 2010 
State-Changed-Why:  
bsdlabel(8) fixed in head, stable/8 and stable/7. I don't consider the 
malloc behavior as a bug but if you still want to pursue the malloc 
change, I suggest trying to contact jasone@ directly. Thanks! 

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