On Tue, 27 Jan 2015, Pedro F. Giffuni wrote:

Log:
 Fix resource leak and dereference after NULL.

 process.c:
 Protect access against NULL.

 main.c:
 Prevent outfile overwrite resource leak.
...
Modified: head/usr.bin/sed/main.c
==============================================================================
--- head/usr.bin/sed/main.c     Tue Jan 27 18:56:46 2015        (r277801)
+++ head/usr.bin/sed/main.c     Tue Jan 27 18:58:24 2015        (r277802)
@@ -411,6 +411,8 @@ mf_fgets(SPACE *sp, enum e_spflag spflag
                        unlink(tmpfname);
                        if ((outfile = fopen(tmpfname, "w")) == NULL)
                                err(1, "%s", fname);
+                       if (outfile != NULL && outfile != stdout)
+                               fclose(outfile);
                        fchown(fileno(outfile), sb.st_uid, sb.st_gid);
                        fchmod(fileno(outfile), sb.st_mode & ALLPERMS);
                        outfname = tmpfname;

This is mismerged at best.  It just breaks the new outfile by closing it.
The check in it makes no sense in this contents, since the freshly-opened
outfile cannot be NULL (since the open succeeded) or stdout (fopen()
cannot return a pointer to an already-open stream, so it can only return
stdout if the stdout pointer is garbage, but then it is not really stdout).

Bruce
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to