Skip to content

Commit 096f46e

Browse files
committed
Fix for memory mgmt in variable expansion (Solaris 105-CR7032068)
This upstreams a Solaris patch: https://github.com/oracle/solaris-userland/blob/master/components/ksh93/patches/105-CR7032068.patch No other information is publicly available but this has been in production use on Solaris for a long time. It looks like this is intended to avoid an invalid free().
1 parent 37637ab commit 096f46e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cmd/ksh93/sh/macro.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ static int varsub(Mac_t *mp)
10711071
{
10721072
register int c;
10731073
register int type=0; /* M_xxx */
1074-
register char *v,*argp=0;
1074+
register char *v, *new_v=0, *argp=0;
10751075
register Namval_t *np = NIL(Namval_t*);
10761076
register int dolg=0, mode=0;
10771077
Lex_t *lp = (Lex_t*)mp->shp->lex_context;
@@ -1450,6 +1450,7 @@ static int varsub(Mac_t *mp)
14501450
if((mp->let || (mp->arith&&nv_isattr(np,(NV_LJUST|NV_RJUST|NV_ZFILL)))) && !nv_isattr(np,NV_INTEGER) && (offset==0 || isspace(c) || strchr(",.+-*/=%&|^?!<>",c)))
14511451
mp->zeros = 1;
14521452
}
1453+
new_v = v = strdup(v);
14531454
if(savptr==stakptr(0))
14541455
stkseek(stkp,offset);
14551456
else
@@ -2018,6 +2019,8 @@ static int varsub(Mac_t *mp)
20182019
}
20192020
if(np)
20202021
nv_close(np);
2022+
if(new_v)
2023+
free(new_v);
20212024
if(pattern)
20222025
free(pattern);
20232026
if(repstr)
@@ -2026,6 +2029,8 @@ static int varsub(Mac_t *mp)
20262029
free(idx);
20272030
return(1);
20282031
nosub:
2032+
if(new_v)
2033+
free(new_v);
20292034
if(type==M_BRACE && sh_lexstates[ST_NORM][c]==S_BREAK)
20302035
{
20312036
fcseek(-1);

0 commit comments

Comments
 (0)