summaryrefslogtreecommitdiffstats
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2015-01-27 18:58:24 +0000
committerpfg <pfg@FreeBSD.org>2015-01-27 18:58:24 +0000
commit99cd6d78b4a7cc473e474ee9d0c7d3d07092b6eb (patch)
tree4a87103f4449f4a603b2e0966844e640a9199520 /usr.bin/sed
parent6f1ff22daed390f1f07033c0d77c25dc48b5f3e1 (diff)
downloadFreeBSD-src-99cd6d78b4a7cc473e474ee9d0c7d3d07092b6eb.zip
FreeBSD-src-99cd6d78b4a7cc473e474ee9d0c7d3d07092b6eb.tar.gz
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
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/main.c2
-rw-r--r--usr.bin/sed/process.c2
2 files changed, 3 insertions, 1 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index 029a79f..dafb0bd 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -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;
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index cdfba81..daabfd8 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -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
OpenPOWER on IntegriCloud