1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +00:00

Improved 'typeset -xu'/'typeset -xl' fix (re: fdb9781e) (#147)

'typeset -xu' and 'typeset -xl' would export the variable but fail
to change case in the value as the check between old and new
attributes did not provide the necesssary insight for lower or
upper case transcoding due to the lower or upper case attribute
being set within typeset.c prior to calling name.c nv_newattr
function.

Previous rhbz#1188377 patch added a conditional check for size==-1
which in effect caused the nv_newattr export code block return
optimization to never be executed as one cannot set any attributes
using the readonly builtin. By altering the size==-1 check to !trans
the export only optimization can run.

Also, the rhbz#1188377 patch altered new_attr function by setting
the new size to oldsize if run by the readonly builtin. The result
of setting size==oldsize allowed the succeeding if statement to
run more frequently and if size was a non-zero value resulted in
nv_setsize resetting the value to what it already was. Investigation
yielded that size was always 0 coming from the readonly builtin.

src/cmd/ksh93/bltins/typeset.c:
- Remove the setting of tdata.argnum to -1 as it is not needed due to
  existing name.c nv_newattr() logic.

src/cmd/ksh93/sh/name.c: nv_newattr():
- Corrected the export only check optimization by using !trans instead
  of using size==-1.
- Removed previous condition check to set size=oldsize if coming from
  the readonly builtin. nv_newattr already had existing logic to
  prevent changing the size via nv_setsize as size is always 0 when
  coming from readonly builtin.
This commit is contained in:
hyenias 2020-11-26 08:30:24 -05:00 committed by GitHub
parent 02e4f2da9e
commit 95fe07d869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 9 deletions

6
NEWS
View file

@ -3,6 +3,12 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs. Any uppercase BUG_* names are modernish shell bug IDs.
2020-10-21:
- Fixed: More concisely correct the exporting of uppercase and lowercase
variables when only the export and change case attributes were applied.
This fix improves upon the previous 2020-09-30 modifications.
2020-10-06: 2020-10-06:
- The security of virtual/non-forking subshells that locally change the present - The security of virtual/non-forking subshells that locally change the present

View file

@ -94,7 +94,6 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context)
memset((void*)&tdata,0,sizeof(tdata)); memset((void*)&tdata,0,sizeof(tdata));
tdata.sh = context->shp; tdata.sh = context->shp;
tdata.aflag = '-'; tdata.aflag = '-';
tdata.argnum = -1; /* tell nv_newattr() that we should not change size */
while((flag = optget(argv,*command=='e'?sh_optexport:sh_optreadonly))) switch(flag) while((flag = optget(argv,*command=='e'?sh_optexport:sh_optreadonly))) switch(flag)
{ {
case 'p': case 'p':

View file

@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> * * David Korn <dgk@research.att.com> *
* * * *
***********************************************************************/ ***********************************************************************/
#define SH_RELEASE "93u+m 2020-10-06" #define SH_RELEASE "93u+m 2020-10-21"

View file

@ -2938,28 +2938,29 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size)
errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np)); errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np));
/* handle attributes that do not change data separately */ /* handle attributes that do not change data separately */
n = np->nvflag; n = np->nvflag;
trans = !(n&NV_INTEGER) && (n&(NV_LTOU|NV_UTOL)); trans = !(n&NV_INTEGER) && (n&(NV_LTOU|NV_UTOL)); /* transcode to lower or upper case */
if(newatts&NV_EXPORT) if(newatts&NV_EXPORT)
nv_offattr(np,NV_IMPORT); nv_offattr(np,NV_IMPORT);
if(((n^newatts)&NV_EXPORT)) if(((n^newatts)&NV_EXPORT)) /* EXPORT attribute has been toggled */
{ {
/* record changes to the environment */ /* record changes to the environment */
if(n&NV_EXPORT) if(n&NV_EXPORT)
{ {
/* EXPORT exists on old attributes therefore not on new */
nv_offattr(np,NV_EXPORT); nv_offattr(np,NV_EXPORT);
env_delete(shp->env,nv_name(np)); env_delete(shp->env,nv_name(np));
} }
else else
{ {
/* EXPORT is now turned on for new attributes */
nv_onattr(np,NV_EXPORT); nv_onattr(np,NV_EXPORT);
sh_envput(shp->env,np); sh_envput(shp->env,np);
} }
if((n^newatts)==NV_EXPORT && size==-1) if((n^newatts)==NV_EXPORT && !trans)
/* Only EXPORT attribute has changed and thus all work has been done. */
return; return;
} }
oldsize = nv_size(np); oldsize = nv_size(np);
if(size==-1)
size = oldsize;
if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0) if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0)
{ {
if(size) if(size)