summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-07-25 15:04:15 +0000
committerpfg <pfg@FreeBSD.org>2016-07-25 15:04:15 +0000
commitd505cd471648cf5c8558bd073eab348d34e3312e (patch)
tree3ae8ca129f50238d1d109ead7b38dfcb7355fdae /usr.bin
parente9e84b258534867ada8546cd53545ae93c94c5cf (diff)
downloadFreeBSD-src-d505cd471648cf5c8558bd073eab348d34e3312e.zip
FreeBSD-src-d505cd471648cf5c8558bd073eab348d34e3312e.tar.gz
MFC r302911:
mail(1): Avoid closing negative file descriptors. CID: 1008105, 1008106
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