ash: fix miscalculation of memory needed for eval tree

found by Timo Teras (timo.teras AT iki.fi)
This commit is contained in:
Denis Vlasenko 2008-11-21 10:36:36 +00:00
parent b8baf407aa
commit 340299a8bc

View File

@ -536,6 +536,7 @@ static const char dolatstr[] ALIGN1 = {
#define NHERE 24 #define NHERE 24
#define NXHERE 25 #define NXHERE 25
#define NNOT 26 #define NNOT 26
#define N_NUMBER 27
union node; union node;
@ -7546,43 +7547,44 @@ commandcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
/* ============ eval.c */ /* ============ eval.c */
static int funcblocksize; /* size of structures in function */ static int funcblocksize; /* size of structures in function */
static int funcstringsize; /* size of strings in node */ static int funcstringsize; /* size of strings in node */
static void *funcblock; /* block to allocate function from */ static void *funcblock; /* block to allocate function from */
static char *funcstring; /* block to allocate strings from */ static char *funcstring; /* block to allocate strings from */
/* flags in argument to evaltree */ /* flags in argument to evaltree */
#define EV_EXIT 01 /* exit after evaluating tree */ #define EV_EXIT 01 /* exit after evaluating tree */
#define EV_TESTED 02 /* exit status is checked; ignore -e flag */ #define EV_TESTED 02 /* exit status is checked; ignore -e flag */
#define EV_BACKCMD 04 /* command executing within back quotes */ #define EV_BACKCMD 04 /* command executing within back quotes */
static const short nodesize[26] = { static const short nodesize[N_NUMBER] = {
SHELL_ALIGN(sizeof(struct ncmd)), [NCMD ] = SHELL_ALIGN(sizeof(struct ncmd)),
SHELL_ALIGN(sizeof(struct npipe)), [NPIPE ] = SHELL_ALIGN(sizeof(struct npipe)),
SHELL_ALIGN(sizeof(struct nredir)), [NREDIR ] = SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nredir)), [NBACKGND ] = SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nredir)), [NSUBSHELL] = SHELL_ALIGN(sizeof(struct nredir)),
SHELL_ALIGN(sizeof(struct nbinary)), [NAND ] = SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)), [NOR ] = SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)), [NSEMI ] = SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nif)), [NIF ] = SHELL_ALIGN(sizeof(struct nif)),
SHELL_ALIGN(sizeof(struct nbinary)), [NWHILE ] = SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nbinary)), [NUNTIL ] = SHELL_ALIGN(sizeof(struct nbinary)),
SHELL_ALIGN(sizeof(struct nfor)), [NFOR ] = SHELL_ALIGN(sizeof(struct nfor)),
SHELL_ALIGN(sizeof(struct ncase)), [NCASE ] = SHELL_ALIGN(sizeof(struct ncase)),
SHELL_ALIGN(sizeof(struct nclist)), [NCLIST ] = SHELL_ALIGN(sizeof(struct nclist)),
SHELL_ALIGN(sizeof(struct narg)), [NDEFUN ] = SHELL_ALIGN(sizeof(struct narg)),
SHELL_ALIGN(sizeof(struct narg)), [NARG ] = SHELL_ALIGN(sizeof(struct narg)),
SHELL_ALIGN(sizeof(struct nfile)), [NTO ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)), [NTO2 ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)), [NCLOBBER ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)), [NFROM ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct nfile)), [NFROMTO ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct ndup)), [NAPPEND ] = SHELL_ALIGN(sizeof(struct nfile)),
SHELL_ALIGN(sizeof(struct ndup)), [NTOFD ] = SHELL_ALIGN(sizeof(struct ndup)),
SHELL_ALIGN(sizeof(struct nhere)), [NFROMFD ] = SHELL_ALIGN(sizeof(struct ndup)),
SHELL_ALIGN(sizeof(struct nhere)), [NHERE ] = SHELL_ALIGN(sizeof(struct nhere)),
SHELL_ALIGN(sizeof(struct nnot)), [NXHERE ] = SHELL_ALIGN(sizeof(struct nhere)),
[NNOT ] = SHELL_ALIGN(sizeof(struct nnot)),
}; };
static void calcsize(union node *n); static void calcsize(union node *n);