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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cron/at.c
          +++ new/usr/src/cmd/cron/at.c
↓ open down ↓ 93 lines elided ↑ open up ↑
  94   94  static int list_jobs(int, char **, int, int);
  95   95  static int remove_jobs(int, char **, char *);
  96   96  static void usage(void);
  97   97  static void catch(int);
  98   98  static void copy(char *, FILE *, int);
  99   99  static void atime(struct tm *, struct tm *);
 100  100  static int not_this_project(char *);
 101  101  static char *mkjobname(time_t);
 102  102  static time_t parse_time(char *);
 103  103  static time_t gtime(struct tm *);
      104 +static void escapestr(char *);
 104  105  void atabort(char *)__NORETURN;
 105  106  void yyerror(void);
 106  107  extern int yyparse(void);
 107  108  
 108  109  extern void     audit_at_delete(char *, char *, int);
 109  110  extern int      audit_at_create(char *, int);
 110  111  extern int      audit_cron_is_anc_name(char *);
 111  112  extern int      audit_cron_delete_anc_file(char *, char *);
 112  113  
 113  114  /*
↓ open down ↓ 425 lines elided ↑ open up ↑
 539  540          for (i = 0; i < tptr->tm_mon; ++i)
 540  541                  tv += dmsize[i];
 541  542          tv += tptr->tm_mday - 1;
 542  543          tv = 24 * tv + tptr->tm_hour;
 543  544          tv = 60 * tv + tptr->tm_min;
 544  545          tv = 60 * tv + tptr->tm_sec;
 545  546          return (tv);
 546  547  }
 547  548  
 548  549  /*
      550 + * Escape a string to be used inside the job shell script.
      551 + */
      552 +static void
      553 +escapestr(char *str)
      554 +{
      555 +        char c;
      556 +        putchar('\'');
      557 +        while ((c = *str++) != '\0') {
      558 +                if (c != '\'')
      559 +                        putchar(c);
      560 +                else
      561 +                        printf("\'\\\'\'"); /* ' -> '\'' */
      562 +        }
      563 +        putchar('\'');
      564 +}
      565 +
      566 +/*
 549  567   * make job file from proto + stdin
 550  568   */
 551  569  static void
 552  570  copy(char *jobfile, FILE *inputfile, int when)
 553  571  {
 554  572          int c;
 555  573          FILE *pfp;
 556  574          char *shell;
 557  575          char    dirbuf[PATH_MAX + 1];
 558  576          char    line[LINE_MAX];
↓ open down ↓ 112 lines elided ↑ open up ↑
 671  689                                  atabort(CANTCHUID);
 672  690                          }
 673  691                          if (getcwd(dirbuf, sizeof (dirbuf)) == NULL) {
 674  692                                  atabort(
 675  693                                      "can't obtain current working directory");
 676  694                          }
 677  695                          /* change back afterwards */
 678  696                          if (seteuid(effeusr) < 0) {
 679  697                                  atabort(CANTCHUID);
 680  698                          }
 681      -                        printf("%s", dirbuf);
      699 +                        escapestr(dirbuf);
 682  700                          break;
 683  701                  case 'm':
 684  702                          printf("%o", um);
 685  703                          break;
 686  704                  case '<':
 687  705                          if (ulimit_flag) {
 688  706                                  if (getrlimit(RLIMIT_FSIZE, &rlp) == 0) {
 689  707                                          if (rlp.rlim_cur == RLIM_INFINITY)
 690  708                                                  printf("ulimit unlimited\n");
 691  709                                          else
↓ open down ↓ 297 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX