mail(1): Avoid closing negative file descriptors.

CID:		1008105, 1008106
MFC after:	1 week
This commit is contained in:
Pedro F. Giffuni 2016-07-15 19:43:24 +00:00
parent 1c1093d6d6
commit c433bea8c0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=302911
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);
}
/*