From 9f980ba65a13847fe8a4dcbf593bef7ed9adbacd Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 2 Feb 2021 11:52:54 +0000 Subject: [PATCH] sh_setmatch(): fix node size calculation This fixes the function that sets ${.sh.match}. Patch from OpenSUSE: https://build.opensuse.org/package/view_file/shells/ksh/ksh93-limit-name-len.dif src/cmd/ksh93/sh/init.c: sh_setmatch(): - Fix node size calculation, possibly preventing data corruption. src/cmd/ksh93/include/ulimit.h: Limit_t: - Defining the 'name' struct member as 'char name[16]' makes no sense as the name is being initialised statically in data/limits.c; just make it a 'char *name' pointer. --- src/cmd/ksh93/include/ulimit.h | 2 +- src/cmd/ksh93/sh/init.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/ksh93/include/ulimit.h b/src/cmd/ksh93/include/ulimit.h index a0e63304b887..5d05c673a654 100644 --- a/src/cmd/ksh93/include/ulimit.h +++ b/src/cmd/ksh93/include/ulimit.h @@ -157,7 +157,7 @@ typedef struct Limit_s { - const char name[16]; + const char* name; const char* description; int index; const char* conf; diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 3a0271b928e3..f7aa10966cb0 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -161,7 +161,7 @@ struct match char *val; char *rval[2]; regoff_t *match; - char node[NV_MINSZ+sizeof(char*)]; + char node[NV_MINSZ+sizeof(char*)+sizeof(Dtlink_t)]; regoff_t first; int vsize; int nmatch; @@ -721,7 +721,7 @@ static int hasgetdisc(register Namfun_t *fp) void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t match[],int index) { struct match *mp = &ip->SH_MATCH_init; - Namval_t *np = nv_namptr(mp->node,0); + Namval_t *np = (Namval_t*)(&(mp->node[0])); register int i,n,x; unsigned int savesub = shp->subshell; Namarr_t *ap = nv_arrayptr(SH_MATCHNOD);