summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-05 20:47:20 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2009-10-05 20:47:20 +0000
commitfeaac10ee46c23f3f1c68c2413d5721633c058af (patch)
treee0db474c3c7b1564f64bc1157b7b23a22fa46055 /usr.bin
parent883437ccf6d9931831d1a591ac38b72ed749138a (diff)
open the -f inputfile before letting lower-down functions call chdir()
and move us to where we cannot open it. problem spotted by austin ok millert
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/at/at.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/usr.bin/at/at.c b/usr.bin/at/at.c
index d32a5b65e02..42b102695e2 100644
--- a/usr.bin/at/at.c
+++ b/usr.bin/at/at.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: at.c,v 1.54 2007/09/05 08:02:21 moritz Exp $ */
+/* $OpenBSD: at.c,v 1.55 2009/10/05 20:47:19 deraadt Exp $ */
/*
* at.c : Put file into atrun queue
@@ -42,7 +42,7 @@
#define TIMESIZE 50 /* Size of buffer passed to strftime() */
#ifndef lint
-static const char rcsid[] = "$OpenBSD: at.c,v 1.54 2007/09/05 08:02:21 moritz Exp $";
+static const char rcsid[] = "$OpenBSD: at.c,v 1.55 2009/10/05 20:47:19 deraadt Exp $";
#endif
/* Variables to remove from the job's environment. */
@@ -55,7 +55,6 @@ char *no_export[] =
int program = AT; /* default program mode */
char atfile[MAX_FNAME]; /* path to the at spool file */
int fcreated; /* whether or not we created the file yet */
-char *atinput = NULL; /* where to get input from */
char atqueue = 0; /* which queue to examine for jobs (atq) */
char vflag = 0; /* show completed but unremoved jobs (atq) */
char force = 0; /* suppress errors (atrm) */
@@ -189,7 +188,7 @@ writefile(const char *cwd, time_t runtimer, char queue)
struct passwd *pass_entry;
struct tm runtime;
int fdes, lockdes, fd2;
- FILE *fp, *fpin;
+ FILE *fp;
struct sigaction act;
char **atenv;
int ch;
@@ -290,11 +289,6 @@ writefile(const char *cwd, time_t runtimer, char queue)
shell = _PATH_BSHELL;
}
- if (atinput != NULL) {
- fpin = freopen(atinput, "r", stdin);
- if (fpin == NULL)
- perr("Cannot open input file");
- }
(void)fprintf(fp, "#!/bin/sh\n# atrun uid=%lu gid=%lu\n# mail %*s %d\n",
(unsigned long)real_uid, (unsigned long)real_gid,
MAX_UNAME, mailname, send_mail);
@@ -930,6 +924,7 @@ int
main(int argc, char **argv)
{
time_t timer = -1;
+ char *atinput = NULL; /* where to get input from */
char queue = DEFAULT_AT_QUEUE;
char queue_set = 0;
char *options = "q:f:t:bcdlmrv"; /* default options for at */
@@ -1046,6 +1041,18 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
+ switch (program) {
+ case AT:
+ case BATCH:
+ if (atinput != NULL) {
+ if (freopen(atinput, "r", stdin) == NULL)
+ perr("Cannot open input file");
+ }
+ break;
+ default:
+ ;
+ }
+
if (getcwd(cwd, sizeof(cwd)) == NULL)
perr("Cannot get current working directory");