aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/mail
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-07-15 19:43:24 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-07-15 19:43:24 +0000
commitc433bea8c07205a1832105f524bc8b04c2431b20 (patch)
tree522858a6e9ffe52ad99c9336e13f8622b0ad674e /usr.bin/mail
parent1c1093d6d63da102fde664995fe5d9874828d15d (diff)
downloadsrc-c433bea8c07205a1832105f524bc8b04c2431b20.tar.gz
src-c433bea8c07205a1832105f524bc8b04c2431b20.zip
mail(1): Avoid closing negative file descriptors.
CID: 1008105, 1008106 MFC after: 1 week
Notes
Notes: svn path=/head/; revision=302911
Diffstat (limited to 'usr.bin/mail')
-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 a9607550c105..4b9bcda3a7ed 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 8fc2f64ccac3..0da7b3b30a68 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);
}
/*