Print this page
5433 at(1) doesn't properly handle being invoked from a path containing spaces

@@ -99,10 +99,11 @@
 static void atime(struct tm *, struct tm *);
 static int not_this_project(char *);
 static char *mkjobname(time_t);
 static time_t parse_time(char *);
 static time_t gtime(struct tm *);
+static void escapestr(char *);
 void atabort(char *)__NORETURN;
 void yyerror(void);
 extern int yyparse(void);
 
 extern void     audit_at_delete(char *, char *, int);

@@ -544,10 +545,27 @@
         tv = 60 * tv + tptr->tm_sec;
         return (tv);
 }
 
 /*
+ * Escape a string to be used inside the job shell script.
+ */
+static void
+escapestr(char *str)
+{
+        char c;
+        putchar('\'');
+        while ((c = *str++) != '\0') {
+                if (c != '\'')
+                        putchar(c);
+                else
+                        printf("\'\\\'\'"); /* ' -> '\'' */
+        }
+        putchar('\'');
+}
+
+/*
  * make job file from proto + stdin
  */
 static void
 copy(char *jobfile, FILE *inputfile, int when)
 {

@@ -676,11 +694,11 @@
                         }
                         /* change back afterwards */
                         if (seteuid(effeusr) < 0) {
                                 atabort(CANTCHUID);
                         }
-                        printf("%s", dirbuf);
+                        escapestr(dirbuf);
                         break;
                 case 'm':
                         printf("%o", um);
                         break;
                 case '<':