mail(1): Avoid closing negative file descriptors.

CID:		1008105, 1008106
MFC after:	1 week
This commit is contained in:
pfg 2016-07-15 19:43:24 +00:00
parent f4f3cadf4f
commit 8808ec7c8c
2 changed files with 6 additions and 2 deletions

View File

@ -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);

View File

@ -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);
}
/*