1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
From: Christian Kastner <ckk@kvr.at>
Date: Tue, 22 Dec 2015 15:55:38 +0100
Subject: crontab: warn about missing newline
Make crontab(1) refuse to add/replace a crontab with a missing newline before
EOF. The daemon will either not execute the last entry, or refuse to execute
the entire crontab (depending on the implementation).
Bug-Debian: https://bugs.debian.org/79037
Forwarded: no
Last-Update: 2015-12-22
---
crontab.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/crontab.c b/crontab.c
index 95afc4a..3a7d8f1 100644
--- a/crontab.c
+++ b/crontab.c
@@ -509,6 +509,7 @@ replace_cmd() {
char n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
FILE *tmp;
int ch, eof;
+ int nl = FALSE;
entry *e;
time_t now = time(NULL);
char **envp = env_init();
@@ -560,6 +561,8 @@ replace_cmd() {
switch (load_env(envstr, tmp)) {
case ERR:
eof = TRUE;
+ if (envstr[0] == '\0')
+ nl = TRUE;
break;
case FALSE:
e = load_entry(tmp, check_error, pw, envp);
@@ -577,6 +580,13 @@ replace_cmd() {
return (-1);
}
+ if (nl == FALSE) {
+ fprintf(stderr, "new crontab file is missing newline before "
+ "EOF, can't install.\n");
+ fclose(tmp); unlink(tn);
+ return (-1);
+ }
+
#ifdef HAS_FCHOWN
if (fchown(fileno(tmp), ROOT_UID, -1) < OK)
#else
|