Print this page
6565 pargs crashes on growing env

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ptools/pargs/pargs.c
          +++ new/usr/src/cmd/ptools/pargs/pargs.c
↓ open down ↓ 76 lines elided ↑ open up ↑
  77   77  typedef struct pargs_data {
  78   78          struct ps_prochandle *pd_proc;  /* target proc handle */
  79   79          psinfo_t *pd_psinfo;            /* target psinfo */
  80   80          char *pd_locale;                /* target process locale */
  81   81          int pd_conv_flags;              /* flags governing string conversion */
  82   82          iconv_t pd_iconv;               /* iconv conversion descriptor */
  83   83          size_t pd_argc;
  84   84          uintptr_t *pd_argv;
  85   85          char **pd_argv_strs;
  86   86          size_t pd_envc;
       87 +        size_t pd_envc_curr;
  87   88          uintptr_t *pd_envp;
  88   89          char **pd_envp_strs;
  89   90          size_t pd_auxc;
  90   91          auxv_t *pd_auxv;
  91   92          char **pd_auxv_strs;
  92   93          char *pd_execname;
  93   94  } pargs_data_t;
  94   95  
  95   96  #define CONV_USE_ICONV          0x01
  96   97  #define CONV_STRICT_ASCII       0x02
↓ open down ↓ 530 lines elided ↑ open up ↑
 627  628          }
 628  629  }
 629  630  
 630  631  /*ARGSUSED*/
 631  632  static int
 632  633  build_env(void *data, struct ps_prochandle *pr, uintptr_t addr, const char *str)
 633  634  {
 634  635          pargs_data_t *datap = data;
 635  636  
 636  637          if (datap->pd_envp != NULL) {
      638 +                /* env has more items than last time, skip the newer ones */
      639 +                if (datap->pd_envc > datap->pd_envc_curr)
      640 +                        return (0);
      641 +
 637  642                  datap->pd_envp[datap->pd_envc] = addr;
 638  643                  if (str == NULL)
 639  644                          datap->pd_envp_strs[datap->pd_envc] = NULL;
 640  645                  else
 641  646                          datap->pd_envp_strs[datap->pd_envc] = strdup(str);
 642  647          }
 643  648  
 644  649          datap->pd_envc++;
 645  650  
 646  651          return (0);
 647  652  }
 648  653  
 649  654  static void
 650  655  get_env(pargs_data_t *datap)
 651  656  {
 652  657          struct ps_prochandle *pr = datap->pd_proc;
 653  658  
 654  659          datap->pd_envc = 0;
 655  660          (void) Penv_iter(pr, build_env, datap);
      661 +        datap->pd_envc_curr = datap->pd_envc;
 656  662  
 657  663          datap->pd_envp = safe_zalloc(sizeof (uintptr_t) * datap->pd_envc);
 658  664          datap->pd_envp_strs = safe_zalloc(sizeof (char *) * datap->pd_envc);
 659  665  
 660  666          datap->pd_envc = 0;
 661  667          (void) Penv_iter(pr, build_env, datap);
 662  668  }
 663  669  
 664  670  /*
 665  671   * The following at_* routines are used to decode data from the aux vector.
↓ open down ↓ 896 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX