svn commit: r277802 - head/usr.bin/sed
Pedro F. Giffuni
pfg at FreeBSD.org
Tue Jan 27 18:58:25 UTC 2015
Author: pfg
Date: Tue Jan 27 18:58:24 2015
New Revision: 277802
URL: https://svnweb.freebsd.org/changeset/base/277802
Log:
Fix resource leak and dereference after NULL.
process.c:
Protect access against NULL.
main.c:
Prevent outfile overwrite resource leak.
CID: 271181
CID: 1006930
Obtained from: NetBSD
MFC after: 3 days
Modified:
head/usr.bin/sed/main.c
head/usr.bin/sed/process.c
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;
Modified: head/usr.bin/sed/process.c
==============================================================================
--- head/usr.bin/sed/process.c Tue Jan 27 18:56:46 2015 (r277801)
+++ head/usr.bin/sed/process.c Tue Jan 27 18:58:24 2015 (r277802)
@@ -324,7 +324,7 @@ applies(struct s_command *cp)
} else
r = 1;
}
- } else if (MATCH(cp->a1)) {
+ } else if (cp->a1 && MATCH(cp->a1)) {
/*
* If the second address is a number less than or
* equal to the line number first selected, only
More information about the svn-src-head
mailing list