Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Aug 2012 14:22:14 GMT
From:      Mark Johnston <markjdb@gmail.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/171187: [patch][libfetch] missing returns in error cases in file.c
Message-ID:  <201208301422.q7UEMESc090940@red.freebsd.org>
Resent-Message-ID: <201208301430.q7UEU3iG084297@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         171187
>Category:       bin
>Synopsis:       [patch][libfetch] missing returns in error cases in file.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 30 14:30:03 UTC 2012
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



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