PR/28744: Ed Ravin: crontab with fewer than 3 comment lines dumps core

in crontab -l.
The problem is that the skip_header code has a side effect of trying to
write to the new temporary cron tab if we run out of comments. Since we
don't have an output file in -l, we core-dump trying to fputc to NULL.
Simplify the logic so that we don't write in the skip_header function,
and we always return the first character after the comment lines to the
caller, skipping the '\n'.
This commit is contained in:
christos 2004-12-22 00:49:14 +00:00
parent 735ac78567
commit 36e8d2b792
1 changed files with 9 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: crontab.c,v 1.23 2004/10/30 17:14:36 dsl Exp $ */
/* $NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 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.23 2004/10/30 17:14:36 dsl Exp $");
__RCSID("$NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 christos Exp $");
#endif
#endif
@ -271,16 +271,16 @@ skip_header(pch, f)
ch = get_char(f);
if (EOF == ch)
break;
if ('#' != ch) {
putc(ch, NewCrontab);
if ('#' != ch)
break;
}
while (EOF != (ch = get_char(f)))
if (ch == '\n')
break;
if (EOF == ch)
break;
}
if (ch == '\n')
ch = get_char(f);
*pch = ch;
}
@ -306,7 +306,7 @@ list_cmd() {
*/
Set_LineNum(1)
skip_header(&ch, f);
while (EOF != (ch = get_char(f)))
for (; EOF != ch; ch = get_char(f))
putchar(ch);
fclose(f);
}
@ -393,9 +393,8 @@ edit_cmd() {
/* copy the rest of the crontab (if any) to the temp file.
*/
if (EOF != ch)
while (EOF != (ch = get_char(f)))
putc(ch, NewCrontab);
for (; EOF != ch; ch = get_char(f))
putc(ch, NewCrontab);
fclose(f);
if (fflush(NewCrontab) < OK) {
perror(Filename);
@ -589,7 +588,7 @@ replace_cmd() {
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.23 2004/10/30 17:14:36 dsl Exp $");
"$NetBSD: crontab.c,v 1.24 2004/12/22 00:49:14 christos Exp $");
/* copy the crontab to the tmp
*/