1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Don't import/export readonly attribute via magic A__z env var

While automagically importing/exporting ksh variable attributes via
the environment is probably a misfeature in general (now disabled
for POSIX standard mode), doing so with the readonly attribute is
particularly problematic. Scripts can take into account the
possibility of importing unwanted attributes by unsetting or
typesetting variables before using them. But there is no way for a
script to get rid of an unwanted imported readonly variable. This
is a possible attack vector with no possible mitigation.

This commit blocks both the import and the export of the readonly
attribute through the environment. I consider it a security fix.

src/cmd/ksh93/sh/init.c: env_import_attributes():
- Clear NV_RDONLY from imported attributes before applying them.

src/cmd/ksh93/sh/name.c: sh_envgen():
- Remove NV_RDONLY from bitmask defining attributes to export.
This commit is contained in:
Martijn Dekker 2021-04-21 03:56:03 +01:00
parent f28bce61a7
commit 7954855f21
4 changed files with 10 additions and 1 deletions

View file

@ -2241,7 +2241,7 @@ char **sh_envgen(void)
/* Export variable attributes into env var named by e_envmarker, unless POSIX mode is on */
cp = data.attval = strcopy(*data.argnam,e_envmarker);
if(!sh_isoption(SH_POSIX))
nv_scan(shp->var_tree, attstore,&data,0,(NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
nv_scan(shp->var_tree, attstore,&data,0,(NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
*data.attval = 0;
if(cp!=data.attval)
data.argnam++;