this came up recently and ksh93t was changed
to ignore but pass through malformed environment variables

On Tue, 07 Oct 2008 17:09:01 +0200 Michal Hlavinka wrote:
> We've found that ksh removes some variables from environment (for example
> variables containing space or hyphen). If you use tcsh, set these 
> variables, run
> ksh and again tcsh, these wariables will be gone. (tcsh and again tcsh 
> works fine.)

> (bugzilla: #464156)

> Excerpt from POSIX
> (http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html):

> Environment variable names used by the utilities in the Shell and Utilities
> volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, 
> digits, and
> the '_' (underscore) from the characters defined in Portable Character 
> Set and
> do not begin with a digit. Other characters may be permitted by an
> implementation; applications shall tolerate the presence of such names.
> Uppercase and lowercase letters shall retain their unique identities and 
> shall
> not be folded together. The name space of environment variable names 
> containing
> lowercase letters is reserved for applications. Applications can define any
> environment variables with names from this name space without modifying the
> behavior of the standard utilities.

> "...applications shall tolerate the presence of such names..."

> Therefore ksh should not alter the environment even though it does not
> allow to access/set such variables.

> I've made patch (attached) to fix this: Variables refused during ksh's 
> initialization
> are kept in separated list and they are added to the environment for 
> executed
> applications.

> It's quite simple with only a few new lines added.

> What's your opinion about this?

> Bye,

> Michal

> --------------070709080808070601040808
> Content-Type: text/x-patch;
>  name="ksh-20080725-keepenv.patch"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline;
>  filename="ksh-20080725-keepenv.patch"

> diff -up ./src/cmd/ksh93/include/nval.h.keepenv ./src/cmd/ksh93/include/nval.h
> --- ./src/cmd/ksh93/include/nval.h.keepenv    2008-07-23 21:40:05.000000000 
> +0200
> +++ ./src/cmd/ksh93/include/nval.h    2008-10-04 21:05:36.000000000 +0200
> @@ -105,6 +105,14 @@ struct Namdecl
>       void            *optinfof;
>  };
>  
> +/* list of strings refused from the environment initialization */
> +struct Linelist_s {
> +     char *line;
> +     struct Linelist_s *next;
> +};
> +
> +extern struct Linelist_s refused_envs;
> +
>  /* attributes of name-value node attribute flags */
>  
>  #define NV_DEFAULT 0
> diff -up ./src/cmd/ksh93/sh/fault.c.keepenv ./src/cmd/ksh93/sh/fault.c
> --- ./src/cmd/ksh93/sh/fault.c.keepenv        2008-06-25 18:25:00.000000000 
> +0200
> +++ ./src/cmd/ksh93/sh/fault.c        2008-10-07 17:01:20.717001479 +0200
> @@ -551,6 +551,7 @@ void sh_done(void *ptr, register int sig
>       Shell_t *shp = (Shell_t*)ptr;
>       register char *t;
>       register int savxit = shp->exitval;
> +     register struct Linelist_s *refenv = refused_envs.next, *freeval;
>       shp->trapnote = 0;
>       indone=1;
>       if(sig==0)
> @@ -584,6 +585,17 @@ void sh_done(void *ptr, register int sig
>               job_walk(sfstderr,job_terminate,SIGHUP,NIL(char**));
>  #endif       /* JOBS */
>       job_close(shp);
> +
> +     /* free up refused environment strings */
> +     while(refenv)
> +     {
> +             freeval = refenv;
> +             if (freeval->line) free(freeval->line);
> +             free(freeval);
> +             refenv = refenv->next;
> +     }
> +     refused_envs.next = NULL;
> +
>       if(nv_search("VMTRACE", shp->var_tree,0))
>               strmatch((char*)0,(char*)0);
>       sfsync((Sfio_t*)sfstdin);
> diff -up ./src/cmd/ksh93/sh/init.c.keepenv ./src/cmd/ksh93/sh/init.c
> --- ./src/cmd/ksh93/sh/init.c.keepenv 2008-07-17 16:47:43.000000000 +0200
> +++ ./src/cmd/ksh93/sh/init.c 2008-10-04 21:15:17.000000000 +0200
> @@ -1553,6 +1553,7 @@ static void env_init(Shell_t *shp)
>       shp->env = env_open(environ,3);
>       env_delete(shp->env,"_");
>  #endif
> +     struct Linelist_s *refenv = &refused_envs;
>       if(ep)
>       {
>               while(cp= *ep++)
> @@ -1565,6 +1566,16 @@ static void env_init(Shell_t *shp)
>                               np->nvenv = cp;
>                               nv_close(np);
>                       }
> +                     else
> +                     {
> +                             /* refused string */
> +                             refenv->next = (struct Linelist_s *) 
> malloc(sizeof(struct Linelist_s *));
> +                             refenv = refenv->next;
> +                             /* TODO: if envirnon is always accessible and 
> its data */
> +                             /* are not changed at all, use pointers only */
> +                             refenv->line = strdup(cp);
> +                             refenv->next = NULL;
> +                     }
>               }
>               while(cp=next)
>               {
> diff -up ./src/cmd/ksh93/sh/name.c.keepenv ./src/cmd/ksh93/sh/name.c
> --- ./src/cmd/ksh93/sh/name.c.keepenv 2008-07-24 07:05:00.000000000 +0200
> +++ ./src/cmd/ksh93/sh/name.c 2008-10-04 21:24:05.000000000 +0200
> @@ -71,6 +71,8 @@ struct adata
>       char            *attval;
>  };
>  
> +struct Linelist_s    refused_envs = { NULL, NULL };
> +
>  #if SHOPT_TYPEDEF
>      struct sh_type
>      {
> @@ -1849,6 +1851,7 @@ char **sh_envgen(void)
>       register char **er;
>       register int namec;
>       register char *cp;
> +     register struct Linelist_s *refenv = refused_envs.next;
>       struct adata data;
>       data.sh = &sh;
>       data.tp = 0;
> @@ -1856,8 +1859,20 @@ char **sh_envgen(void)
>       nv_offattr(L_ARGNOD,NV_EXPORT);
>       data.attsize = 6;
>       namec = nv_scan(sh.var_tree,nullscan,(void*)0,NV_EXPORT,NV_EXPORT);
> +     while(refenv)
> +     {
> +             namec++;
> +             refenv = refenv->next;
> +     }
>       er = (char**)stakalloc((namec+4)*sizeof(char*));
>       data.argnam = (er+=2);
> +     refenv = refused_envs.next;
> +     while(refenv)
> +     {
> +             *(data.argnam) = stakcopy(refenv->line);
> +             data.argnam++;
> +             refenv = refenv->next;
> +     }
>       nv_scan(sh.var_tree, pushnam,&data,NV_EXPORT, NV_EXPORT);
>       *data.argnam = (char*)stakalloc(data.attsize);
>       cp = data.attval = strcopy(*data.argnam,e_envmarker);

> --------------070709080808070601040808
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline

> _______________________________________________
> ast-developers mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-developers

> --------------070709080808070601040808--

_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to