Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/cron PR/10957: Ed Ravin: Cron does not execute the ...



details:   https://anonhg.NetBSD.org/src/rev/9f2a16ba6a68
branches:  trunk
changeset: 574561:9f2a16ba6a68
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Mar 04 16:46:28 2005 +0000

description:
PR/10957: Ed Ravin: Cron does not execute the last line in crontab if
the trailing newline is missing. Fix by changing crontab(1) to not
allow installation of crontab files with missing trailing newlines.

diffstat:

 usr.sbin/cron/crontab.c |  19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diffs (53 lines):

diff -r e82048d15296 -r 9f2a16ba6a68 usr.sbin/cron/crontab.c
--- a/usr.sbin/cron/crontab.c   Fri Mar 04 16:25:20 2005 +0000
+++ b/usr.sbin/cron/crontab.c   Fri Mar 04 16:46:28 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 christos Exp $    */
+/*     $NetBSD: crontab.c,v 1.25 2005/03/04 16:46:28 christos Exp $    */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -22,7 +22,7 @@
 #if 0
 static char rcsid[] = "Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp";
 #else
-__RCSID("$NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 christos Exp $");
+__RCSID("$NetBSD: crontab.c,v 1.25 2005/03/04 16:46:28 christos Exp $");
 #endif
 #endif
 
@@ -533,7 +533,7 @@
 replace_cmd() {
        char    n[MAX_FNAME], n2[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME];
        FILE    *tmp, *fmaxtabsize;
-       int     ch, eof;
+       int     ch, eof, lastch;
        entry   *e;
        time_t  now = time(NULL);
        char    **envp = env_init();
@@ -588,14 +588,23 @@
        fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n");
        fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
        fprintf(tmp, "# (Cron version -- %s)\n",
-           "$NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 christos Exp $");
+           "$NetBSD: crontab.c,v 1.25 2005/03/04 16:46:28 christos Exp $");
 
        /* copy the crontab to the tmp
         */
        rewind(NewCrontab);
        Set_LineNum(1)
-       while (EOF != (ch = get_char(NewCrontab)))
+       lastch = EOF;
+       while (EOF != (ch = get_char(NewCrontab))) {
                putc(ch, tmp);
+               lastch = ch;
+       }
+       if (lastch != EOF && lastch != '\n') {
+               fprintf(stderr, "%s: missing trailing newline in %s\n",
+                       ProgramName, Filename);
+               fclose(tmp);  unlink(tn);
+               return(-1);
+       }
 
        if (ferror(NewCrontab)) {
                fprintf(stderr, "%s: error while reading %s: %s\n",



Home | Main Index | Thread Index | Old Index