summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-07-25 15:03:14 +0000
committerpfg <pfg@FreeBSD.org>2016-07-25 15:03:14 +0000
commit8925d1cf89b69ae37c22a7e4dceb2848732b3d62 (patch)
treec9ddf82ec1383ed872c10c725ca8ddeb12f4f196 /usr.bin
parentfbb9ed1b222fe59662cb8cc67c250927cf15ff62 (diff)
downloadFreeBSD-src-8925d1cf89b69ae37c22a7e4dceb2848732b3d62.zip
FreeBSD-src-8925d1cf89b69ae37c22a7e4dceb2848732b3d62.tar.gz
MFC r302911:
mail(1): Avoid closing negative file descriptors. CID: 1008105, 1008106 Approved by: re (gjb)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mail/quit.c3
-rw-r--r--usr.bin/mail/v7.local.c5
2 files changed, 6 insertions, 2 deletions
diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c
index a960755..4b9bcda 100644
--- a/usr.bin/mail/quit.c
+++ b/usr.bin/mail/quit.c
@@ -228,7 +228,8 @@ quit(void)
return;
}
(void)Fclose(obuf);
- (void)close(open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600));
+ if ((fd = open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600)) >= 0)
+ (void)close(fd);
if ((obuf = Fopen(mbox, "r+")) == NULL) {
warn("%s", mbox);
(void)Fclose(ibuf);
diff --git a/usr.bin/mail/v7.local.c b/usr.bin/mail/v7.local.c
index 8fc2f64..0da7b3b 100644
--- a/usr.bin/mail/v7.local.c
+++ b/usr.bin/mail/v7.local.c
@@ -68,9 +68,12 @@ findmail(char *user, char *buf, int buflen)
void
demail(void)
{
+ int fd;
if (value("keep") != NULL || rm(mailname) < 0)
- (void)close(open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600));
+ if ((fd = open(mailname, O_CREAT | O_TRUNC | O_WRONLY, 0600)) >=
+ 0)
+ (void)close(fd);
}
/*
OpenPOWER on IntegriCloud