summaryrefslogtreecommitdiff
path: root/usr.sbin/cron
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-03-10 15:09:21 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-03-10 15:09:21 +0000
commit69bf3758891b1a69713cb4681137b499c10be5be (patch)
treedf07febda981634be3a8f5eb7992b225ec62bb71 /usr.sbin/cron
parent209ed04f4ffdf0925834526d5a0cb8c530e70726 (diff)
Do the check for missing command before the un_getchar(); otherwise
the error messages will say line 0. This is because un_getchar('\n', file) will decrement the line count. Noticed by mpech@
Diffstat (limited to 'usr.sbin/cron')
-rw-r--r--usr.sbin/cron/entry.c86
1 files changed, 44 insertions, 42 deletions
diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c
index a4776103e3a..06a560d2ff6 100644
--- a/usr.sbin/cron/entry.c
+++ b/usr.sbin/cron/entry.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: entry.c,v 1.19 2003/03/09 18:13:02 millert Exp $ */
+/* $OpenBSD: entry.c,v 1.20 2003/03/10 15:09:20 millert Exp $ */
/*
* Copyright 1988,1990,1993,1994 by Paul Vixie
@@ -23,7 +23,7 @@
*/
#if !defined(lint) && !defined(LINT)
-static char const rcsid[] = "$OpenBSD: entry.c,v 1.19 2003/03/09 18:13:02 millert Exp $";
+static char const rcsid[] = "$OpenBSD: entry.c,v 1.20 2003/03/10 15:09:20 millert Exp $";
#endif
/* vix 26jan87 [RCS'd; rest of log is in RCS file]
@@ -56,7 +56,7 @@ static const char *ecodes[] =
static char get_list(bitstr_t *, int, int, const char *[], char, FILE *),
get_range(bitstr_t *, int, int, const char *[], char, FILE *),
- get_number(int *, int, const char *[], char, FILE *);
+ get_number(int *, int, const char *[], char, FILE *, const char *);
static int set_element(bitstr_t *, int, int, int);
void
@@ -234,6 +234,12 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
bit_set(e->dow, 7);
}
+ /* check for permature EOL and catch a common typo */
+ if (ch == '\n' || ch == '*') {
+ ecode = e_cmd;
+ goto eof;
+ }
+
/* ch is the first character of a command, or a username */
unget_char(ch, file);
@@ -244,7 +250,7 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
ch = get_string(username, MAX_COMMAND, file, " \t\n");
Debug(DPARS, ("load_entry()...got %s\n",username))
- if (ch == EOF) {
+ if (ch == EOF || ch == '\n' || ch == '*') {
ecode = e_username;
goto eof;
}
@@ -258,12 +264,6 @@ load_entry(FILE *file, void (*error_func)(), struct passwd *pw, char **envp) {
(long)pw->pw_uid, (long)pw->pw_gid))
}
- /* check for a command and catch a common typo (an extra '*') */
- if (ch == EOF || ch == '\n' || ch == '*') {
- ecode = e_cmd;
- goto eof;
- }
-
if ((e->pwd = pw_dup(pw)) == NULL) {
ecode = e_memory;
goto eof;
@@ -461,7 +461,8 @@ get_range(bitstr_t *bits, int low, int high, const char *names[],
if (ch == EOF)
return (EOF);
} else {
- if (EOF == (ch = get_number(&num1, low, names, ch, file)))
+ ch = get_number(&num1, low, names, ch, file, ",- \t\n");
+ if (ch == EOF)
return (EOF);
if (ch != '-') {
@@ -481,7 +482,7 @@ get_range(bitstr_t *bits, int low, int high, const char *names[],
/* get the number following the dash
*/
- ch = get_number(&num2, low, names, ch, file);
+ ch = get_number(&num2, low, names, ch, file, ",- \t\n");
if (ch == EOF)
return (EOF);
}
@@ -501,7 +502,7 @@ get_range(bitstr_t *bits, int low, int high, const char *names[],
* element id, it's a step size. 'low' is
* sent as a 0 since there is no offset either.
*/
- ch = get_number(&num3, 0, PPC_NULL, ch, file);
+ ch = get_number(&num3, 0, PPC_NULL, ch, file, ",- \t\n");
if (ch == EOF || num3 == 0)
return (EOF);
} else {
@@ -525,51 +526,52 @@ get_range(bitstr_t *bits, int low, int high, const char *names[],
}
static char
-get_number(int *numptr, int low, const char *names[], char ch, FILE *file) {
+get_number(int *numptr, int low, const char *names[], char ch, FILE *file,
+ const char *terms) {
char temp[MAX_TEMPSTR], *pc;
- int len, i, all_digits;
+ int len, i;
- /* collect alphanumerics into our fixed-size temp array
- */
pc = temp;
len = 0;
- all_digits = TRUE;
- while (isalnum((unsigned char)ch)) {
+
+ /* first look for a number */
+ while (isdigit((unsigned char)ch)) {
if (++len >= MAX_TEMPSTR)
goto bad;
-
*pc++ = ch;
-
- if (!isdigit((unsigned char)ch))
- all_digits = FALSE;
-
ch = get_char(file);
}
*pc = '\0';
- if (len == 0)
- goto bad;
+ if (len != 0) {
+ /* got a number, check for valid terminator */
+ if (!strchr(terms, ch))
+ goto bad;
+ *numptr = atoi(temp);
+ return (ch);
+ }
- /* try to find the name in the name list
- */
+ /* no numbers, look for a string if we have any */
if (names) {
- for (i = 0; names[i] != NULL; i++) {
- Debug(DPARS|DEXT,
- ("get_num, compare(%s,%s)\n", names[i], temp))
- if (!strcasecmp(names[i], temp)) {
- *numptr = i+low;
- return (ch);
+ while (isalpha((unsigned char)ch)) {
+ if (++len >= MAX_TEMPSTR)
+ goto bad;
+ *pc++ = ch;
+ ch = get_char(file);
+ }
+ *pc = '\0';
+ if (len != 0 && strchr(terms, ch)) {
+ for (i = 0; names[i] != NULL; i++) {
+ Debug(DPARS|DEXT,
+ ("get_num, compare(%s,%s)\n", names[i],
+ temp))
+ if (!strcasecmp(names[i], temp)) {
+ *numptr = i+low;
+ return (ch);
+ }
}
}
}
- /* no name list specified, or there is one and our string isn't
- * in it. either way: if it's all digits, use its magnitude.
- * otherwise, it's an error.
- */
- if (all_digits) {
- *numptr = atoi(temp);
- return (ch);
- }
bad:
unget_char(ch, file);
return (EOF);