From nobody@FreeBSD.org  Thu Aug 30 14:22:14 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id AA0C7106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 30 Aug 2012 14:22:14 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 94F3B8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 30 Aug 2012 14:22:14 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q7UEME3P090941
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 30 Aug 2012 14:22:14 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q7UEMESc090940;
	Thu, 30 Aug 2012 14:22:14 GMT
	(envelope-from nobody)
Message-Id: <201208301422.q7UEMESc090940@red.freebsd.org>
Date: Thu, 30 Aug 2012 14:22:14 GMT
From: Mark Johnston <markjdb@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch][libfetch] missing returns in error cases in file.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171187
>Category:       bin
>Synopsis:       [patch][libfetch] missing returns in error cases in file.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 30 14:30:03 UTC 2012
>Closed-Date:    Fri Sep 28 01:20:21 UTC 2012
>Last-Modified:  Fri Sep 28 01:20:21 UTC 2012
>Originator:     Mark Johnston
>Release:        CURRENT
>Organization:
>Environment:
FreeBSD oddish 10.0-CURRENT FreeBSD 10.0-CURRENT #4 r239361+382bdfb-dirty: Sun Aug 19 23:06:24 EDT 2012     mark@oddish:/home/mark/src/freebsd-obj/usr/home/mark/src/freebsd/sys/GENERIC  amd64
>Description:
Some of the file scheme code doesn't handle errors properly. Specifically, it doesn't return to the caller if an error occurs.
>How-To-Repeat:
The following program segfaults:

#include <sys/param.h>
#include <stdio.h>
#include <fetch.h>
#include <stdlib.h>

int
main()
{
    FILE *f = fetchGetURL("file:///home/mark/nonexistent-file", "");

    return (0);
}
>Fix:
Apply the patch below.

Patch attached with submission follows:

diff --git a/lib/libfetch/file.c b/lib/libfetch/file.c
index 8569ff3..8c1d404 100644
--- a/lib/libfetch/file.c
+++ b/lib/libfetch/file.c
@@ -50,12 +50,15 @@ fetchXGetFile(struct url *u, struct url_stat *us, const char *flags)
 
 	f = fopen(u->doc, "r");
 
-	if (f == NULL)
+	if (f == NULL) {
 		fetch_syserr();
+		return (NULL);
+	}
 
 	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
 		fclose(f);
 		fetch_syserr();
+		return (NULL);
 	}
 
 	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
@@ -78,12 +81,15 @@ fetchPutFile(struct url *u, const char *flags)
 	else
 		f = fopen(u->doc, "w+");
 
-	if (f == NULL)
+	if (f == NULL) {
 		fetch_syserr();
+		return (NULL);
+	}
 
 	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
 		fclose(f);
 		fetch_syserr();
+		return (NULL);
 	}
 
 	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);


>Release-Note:
>Audit-Trail:

From: Mark Johnston <markjdb@gmail.com>
To: bug-followup@FreeBSD.org, markjdb@gmail.com
Cc:  
Subject: Re: kern/171187: [patch][libfetch] missing returns in error cases in file.c
Date: Fri, 31 Aug 2012 09:08:43 -0400

 Hm. I think there's a bug in the PR submission code... this PR's in kern,
 but I remember setting it to be in bin/, and the email I received confirms this:
 
 Thank you very much for your problem report.
 It has the internal identification `bin/171187'.
 The individual assigned to look at your
 report is: freebsd-bugs.
 
 You can access the state of your problem report at any time
 via this link:
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=171187
 
 >Category:       bin
 >Responsible:    freebsd-bugs
 >Synopsis:       [patch][libfetch] missing returns in error cases in file.c
 >Arrival-Date:   Thu Aug 30 14:30:03 UTC 2012
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Sep 2 02:20:30 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171187 
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Sun Sep 2 02:58:38 UTC 2012 
State-Changed-Why:  
awaiting approval 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/171187: commit references a PR
Date: Fri, 14 Sep 2012 12:15:30 +0000 (UTC)

 Author: eadler
 Date: Fri Sep 14 12:15:13 2012
 New Revision: 240495
 URL: http://svn.freebsd.org/changeset/base/240495
 
 Log:
   Adding missing return statements during error conditions.
   
   PR:		kern/171187
   Submitted by:	Mark Johnston <markjdb@gmail.com>
   Reviewed by:	des
   Approved by:	cperciva
   MFC after:	2 weeks
 
 Modified:
   head/lib/libfetch/file.c
 
 Modified: head/lib/libfetch/file.c
 ==============================================================================
 --- head/lib/libfetch/file.c	Fri Sep 14 11:51:49 2012	(r240494)
 +++ head/lib/libfetch/file.c	Fri Sep 14 12:15:13 2012	(r240495)
 @@ -50,12 +50,15 @@ fetchXGetFile(struct url *u, struct url_
  
  	f = fopen(u->doc, "r");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 @@ -78,12 +81,15 @@ fetchPutFile(struct url *u, const char *
  	else
  		f = fopen(u->doc, "w+");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 _______________________________________________
 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: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Fri Sep 14 12:33:44 UTC 2012 
State-Changed-Why:  
committed in r240495 


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

From: Mark Johnston <markjdb@gmail.com>
To: eadler@FreeBSD.org, bug-followup@freebsd.org
Cc:  
Subject: Re: kern/171187: [patch][libfetch] missing returns in error cases in
 file.c
Date: Sat, 15 Sep 2012 17:23:51 -0400

 On Fri, Sep 14, 2012 at 12:33:57PM +0000, eadler@FreeBSD.org wrote:
 > Synopsis: [patch][libfetch] missing returns in error cases in file.c
 > 
 > State-Changed-From-To: analyzed->patched
 > State-Changed-By: eadler
 > State-Changed-When: Fri Sep 14 12:33:44 UTC 2012
 > State-Changed-Why: 
 > committed in r240495
 > 
 > 
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=171187
 
 Thanks! I guess the PR can be closed then.
 
 -Mark

From: Eitan Adler <eadler@freebsd.org>
To: Mark Johnston <markjdb@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: kern/171187: [patch][libfetch] missing returns in error cases in file.c
Date: Sat, 15 Sep 2012 17:27:36 -0400

 On 15 September 2012 17:23, Mark Johnston <markjdb@gmail.com> wrote:
 >> http://www.freebsd.org/cgi/query-pr.cgi?pr=171187
 >
 > Thanks! I guess the PR can be closed then.
 
 FreeBSD has a special meaning for "closed": the issue has been fixed
 in the main "development" branch, and it has been "Merged from
 current"  (MFCed) into the stable/ branches.  I will do this in about
 2 weeks and then close the PR. In the meantime the pr is considered
 "patched".
 
 Thanks for your submission!
 
 
 
 -- 
 Eitan Adler
 Source & Ports committer
 X11, Bugbusting teams

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/171187: commit references a PR
Date: Fri, 28 Sep 2012 01:04:21 +0000 (UTC)

 Author: eadler
 Date: Fri Sep 28 01:04:09 2012
 New Revision: 241016
 URL: http://svn.freebsd.org/changeset/base/241016
 
 Log:
   MFC r240495:
   	Adding missing return statements during error conditions.
   
   PR:		kern/171187
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/9/lib/libfetch/file.c
 Directory Properties:
   stable/9/lib/libfetch/   (props changed)
 
 Modified: stable/9/lib/libfetch/file.c
 ==============================================================================
 --- stable/9/lib/libfetch/file.c	Thu Sep 27 23:31:19 2012	(r241015)
 +++ stable/9/lib/libfetch/file.c	Fri Sep 28 01:04:09 2012	(r241016)
 @@ -50,12 +50,15 @@ fetchXGetFile(struct url *u, struct url_
  
  	f = fopen(u->doc, "r");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 @@ -78,12 +81,15 @@ fetchPutFile(struct url *u, const char *
  	else
  		f = fopen(u->doc, "w+");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 _______________________________________________
 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/171187: commit references a PR
Date: Fri, 28 Sep 2012 01:04:38 +0000 (UTC)

 Author: eadler
 Date: Fri Sep 28 01:04:09 2012
 New Revision: 241017
 URL: http://svn.freebsd.org/changeset/base/241017
 
 Log:
   MFC r240495:
   	Adding missing return statements during error conditions.
   
   PR:		kern/171187
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/8/lib/libfetch/file.c
 Directory Properties:
   stable/8/lib/libfetch/   (props changed)
 
 Modified: stable/8/lib/libfetch/file.c
 ==============================================================================
 --- stable/8/lib/libfetch/file.c	Fri Sep 28 01:04:09 2012	(r241016)
 +++ stable/8/lib/libfetch/file.c	Fri Sep 28 01:04:09 2012	(r241017)
 @@ -50,12 +50,15 @@ fetchXGetFile(struct url *u, struct url_
  
  	f = fopen(u->doc, "r");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 @@ -78,12 +81,15 @@ fetchPutFile(struct url *u, const char *
  	else
  		f = fopen(u->doc, "w+");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 _______________________________________________
 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/171187: commit references a PR
Date: Fri, 28 Sep 2012 01:04:53 +0000 (UTC)

 Author: eadler
 Date: Fri Sep 28 01:04:10 2012
 New Revision: 241018
 URL: http://svn.freebsd.org/changeset/base/241018
 
 Log:
   MFC r240495:
   	Adding missing return statements during error conditions.
   
   PR:		kern/171187
   Approved by:	cperciva (implicit)
 
 Modified:
   stable/7/lib/libfetch/file.c
 Directory Properties:
   stable/7/lib/libfetch/   (props changed)
 
 Modified: stable/7/lib/libfetch/file.c
 ==============================================================================
 --- stable/7/lib/libfetch/file.c	Fri Sep 28 01:04:09 2012	(r241017)
 +++ stable/7/lib/libfetch/file.c	Fri Sep 28 01:04:10 2012	(r241018)
 @@ -49,12 +49,15 @@ fetchXGetFile(struct url *u, struct url_
  
  	f = fopen(u->doc, "r");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	return (f);
 @@ -76,12 +79,15 @@ fetchPutFile(struct url *u, const char *
  	else
  		f = fopen(u->doc, "w+");
  
 -	if (f == NULL)
 +	if (f == NULL) {
  		fetch_syserr();
 +		return (NULL);
 +	}
  
  	if (u->offset && fseeko(f, u->offset, SEEK_SET) == -1) {
  		fclose(f);
  		fetch_syserr();
 +		return (NULL);
  	}
  
  	return (f);
 _______________________________________________
 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: eadler 
State-Changed-When: Fri Sep 28 01:20:19 UTC 2012 
State-Changed-Why:  
Committed. Thanks! 

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