summaryrefslogtreecommitdiffstats
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2014-08-05 01:32:09 +0000
committerpeter <peter@FreeBSD.org>2014-08-05 01:32:09 +0000
commitb2635de2753f7eb19fc8b118f2ac29a3f906e8a3 (patch)
tree84f7fac7af33a4344e8b326115dcb774b66a40ac /usr.sbin/cron
parent4600198022c5ffc16ad7993cec19b51259a9f2bb (diff)
downloadFreeBSD-src-b2635de2753f7eb19fc8b118f2ac29a3f906e8a3.zip
FreeBSD-src-b2635de2753f7eb19fc8b118f2ac29a3f906e8a3.tar.gz
Check gethostname(2) return code - but even if it succeeds it may not
null terminate. Temporarily use "From: $user@$hostname" rather than "From: $user". The latter exposes incompatible behavior if using dma(8). sendmail(8) (and other alternatives) canonify either form on submission (even if masquerading), but dma will leak a non-compliant address to the internet.
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/cron/do_command.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c
index fee4131..8dfd4f6 100644
--- a/usr.sbin/cron/cron/do_command.c
+++ b/usr.sbin/cron/cron/do_command.c
@@ -481,14 +481,17 @@ child_process(e, u)
auto char mailcmd[MAX_COMMAND];
auto char hostname[MAXHOSTNAMELEN];
- (void) gethostname(hostname, MAXHOSTNAMELEN);
+ if (gethostname(hostname, MAXHOSTNAMELEN) == -1)
+ hostname[0] = '\0';
+ hostname[sizeof(hostname) - 1] = '\0';
(void) snprintf(mailcmd, sizeof(mailcmd),
MAILARGS, MAILCMD);
if (!(mail = cron_popen(mailcmd, "w", e))) {
warn("%s", MAILCMD);
(void) _exit(ERROR_EXIT);
}
- fprintf(mail, "From: %s (Cron Daemon)\n", usernm);
+ fprintf(mail, "From: Cron Daemon <%s@%s>\n",
+ usernm, hostname);
fprintf(mail, "To: %s\n", mailto);
fprintf(mail, "Subject: Cron <%s@%s> %s\n",
usernm, first_word(hostname, "."),
OpenPOWER on IntegriCloud