Make sure that the crontab is not an unreasonable size.

(Currently MAXCRONTABSIZE is 256 KB.)
This commit is contained in:
cjs 1999-04-08 21:30:02 +00:00
parent c672e5ca96
commit a1d7b99e1e
1 changed files with 20 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: crontab.c,v 1.12 1999/03/23 22:53:30 thorpej Exp $ */
/* $NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs 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.12 1999/03/23 22:53:30 thorpej Exp $");
__RCSID("$NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs Exp $");
#endif
#endif
@ -32,6 +32,9 @@ __RCSID("$NetBSD: crontab.c,v 1.12 1999/03/23 22:53:30 thorpej Exp $");
*/
#define MAXCRONTABSIZE (1024*256) /* max crontab size == 256 KB */
#define MAIN_PROGRAM
@ -515,6 +518,7 @@ replace_cmd() {
entry *e;
time_t now = time(NULL);
char **envp = env_init();
struct stat statbuf;
(void) snprintf(n, sizeof(n), "tmp.%d", Pid);
(void) snprintf(tn, sizeof(tn), CRON_TAB(n));
@ -523,6 +527,19 @@ replace_cmd() {
return (-2);
}
/* make sure that the crontab is not an unreasonable size
* XXX this is subject to a race condition--fix it if you like.
*/
if (fstat(fileno(NewCrontab), &statbuf)) {
fprintf(stderr, "%s: error stat'ing crontab input: %s\n",
ProgramName, strerror(errno));
return(-2);
}
if (statbuf.st_size > MAXCRONTABSIZE) {
fprintf(stderr, "%s: crontab too large\n", ProgramName);
return(-1);
}
/* write a signature at the top of the file.
*
* VERY IMPORTANT: make sure NHEADER_LINES agrees with this code.
@ -530,7 +547,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.12 1999/03/23 22:53:30 thorpej Exp $");
"$NetBSD: crontab.c,v 1.13 1999/04/08 21:30:02 cjs Exp $");
/* copy the crontab to the tmp
*/