Module Name: src Committed By: christos Date: Sat Jun 21 17:43:04 UTC 2014
Modified Files: src/usr.bin/sed: main.c Log Message: CID 10006930: Prevent outfile overwrite resource leak. To generate a diff of this commit: cvs rdiff -u -r1.27 -r1.28 src/usr.bin/sed/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/sed/main.c diff -u src/usr.bin/sed/main.c:1.27 src/usr.bin/sed/main.c:1.28 --- src/usr.bin/sed/main.c:1.27 Wed Jun 18 10:15:50 2014 +++ src/usr.bin/sed/main.c Sat Jun 21 13:43:04 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.27 2014/06/18 14:15:50 christos Exp $ */ +/* $NetBSD: main.c,v 1.28 2014/06/21 17:43:04 christos Exp $ */ /*- * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson. @@ -39,7 +39,7 @@ #endif #include <sys/cdefs.h> -__RCSID("$NetBSD: main.c,v 1.27 2014/06/18 14:15:50 christos Exp $"); +__RCSID("$NetBSD: main.c,v 1.28 2014/06/21 17:43:04 christos Exp $"); #ifdef __FBSDID __FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $"); #endif @@ -427,6 +427,8 @@ mf_fgets(SPACE *sp, enum e_spflag spflag if (len >= sizeof(tmpfname)) errx(1, "%s: name too long", fname); unlink(tmpfname); + if (outfile != NULL && outfile != stdout) + flose(outfile); if ((outfile = fopen(tmpfname, "w")) == NULL) err(1, "%s", fname); fchown(fileno(outfile), sb.st_uid, sb.st_gid);