diff options
author | pfg <pfg@FreeBSD.org> | 2015-01-30 14:36:02 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-01-30 14:36:02 +0000 |
commit | 5cc53d04db692bfe45a7994a3e3bcf36573d9961 (patch) | |
tree | f62fae80f57715822214b88cfbc58ce3a6ae5cd9 /usr.bin | |
parent | 2f8208fe7786625939fcd121b4e4289a8796786e (diff) | |
download | FreeBSD-src-5cc53d04db692bfe45a7994a3e3bcf36573d9961.zip FreeBSD-src-5cc53d04db692bfe45a7994a3e3bcf36573d9961.tar.gz |
MFC r277802, r277811:
sed: 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
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/sed/main.c | 2 | ||||
-rw-r--r-- | usr.bin/sed/process.c | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 6cdfcda..f907dcd 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -409,6 +409,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) + fclose(outfile); if ((outfile = fopen(tmpfname, "w")) == NULL) err(1, "%s", fname); fchown(fileno(outfile), sb.st_uid, sb.st_gid); diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index cf704f0..91fd7b9 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -314,7 +314,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 |