bin/171187: [patch][libfetch] missing returns in error cases in file.c

Mark Johnston markjdb at gmail.com
Thu Aug 30 14:30:04 UTC 2012


>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 at 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:


More information about the freebsd-bugs mailing list