summaryrefslogtreecommitdiffstats
path: root/contrib/sendmail/mail.local/mail.local.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/sendmail/mail.local/mail.local.c')
-rw-r--r--contrib/sendmail/mail.local/mail.local.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/contrib/sendmail/mail.local/mail.local.c b/contrib/sendmail/mail.local/mail.local.c
index 9ef3fb5..027829f 100644
--- a/contrib/sendmail/mail.local/mail.local.c
+++ b/contrib/sendmail/mail.local/mail.local.c
@@ -18,7 +18,7 @@ SM_IDSTR(copyright,
Copyright (c) 1990, 1993, 1994\n\
The Regents of the University of California. All rights reserved.\n")
-SM_IDSTR(id, "@(#)$Id: mail.local.c,v 8.239 2002/05/24 20:56:32 gshapiro Exp $")
+SM_IDSTR(id, "@(#)$Id: mail.local.c,v 8.239.2.2 2002/09/24 02:09:09 ca Exp $")
#include <stdlib.h>
#include <sm/errstring.h>
@@ -657,6 +657,8 @@ store(from, inbody)
(void) sm_strlcpy(tmpbuf, _PATH_LOCTMP, sizeof tmpbuf);
if ((fd = mkstemp(tmpbuf)) < 0 || (fp = fdopen(fd, "w+")) == NULL)
{
+ if (fd >= 0)
+ (void) close(fd);
mailerr("451 4.3.0", "Unable to open temporary file");
return -1;
}
@@ -1200,7 +1202,8 @@ err3:
#ifdef DEBUG
fprintf(stderr, "reset euid = %d\n", (int) geteuid());
#endif /* DEBUG */
- (void) ftruncate(mbfd, curoff);
+ if (mbfd >= 0)
+ (void) ftruncate(mbfd, curoff);
err1: if (mbfd >= 0)
(void) close(mbfd);
err0: unlockmbox();
@@ -1216,7 +1219,29 @@ err0: unlockmbox();
errcode = "552 5.2.2";
#endif /* EDQUOT */
mailerr(errcode, "%s: %s", path, sm_errstring(errno));
- (void) truncate(path, curoff);
+ mbfd = open(path, O_WRONLY|EXTRA_MODE, 0);
+ if (mbfd < 0
+ || fstat(mbfd, &sb) < 0 ||
+ sb.st_nlink != 1 ||
+ !S_ISREG(sb.st_mode) ||
+ sb.st_dev != fsb.st_dev ||
+ sb.st_ino != fsb.st_ino ||
+# if HAS_ST_GEN && 0 /* AFS returns random values for st_gen */
+ sb.st_gen != fsb.st_gen ||
+# endif /* HAS_ST_GEN && 0 */
+ sb.st_uid != fsb.st_uid
+ )
+ {
+ /* Don't use a bogus file */
+ if (mbfd >= 0)
+ {
+ (void) close(mbfd);
+ mbfd = -1;
+ }
+ }
+
+ /* Attempt to truncate back to pre-write size */
+ goto err3;
}
else
notifybiff(biffmsg);
OpenPOWER on IntegriCloud