sh: Use C99 flexible array instead of accessing array beyond bounds.

Although sufficient memory is available for a longer string in cmdname,
this is undefined behaviour anyway.

Side effect: for alignment reasons, an additional byte of memory is
allocated per hashed command.
This commit is contained in:
Jilles Tjoelker 2012-11-03 22:23:08 +00:00
parent 305921c48e
commit 422c281c83
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=242530

View File

@ -78,7 +78,6 @@ __FBSDID("$FreeBSD$");
#define CMDTABLESIZE 31 /* should be prime */
#define ARB 1 /* actual size determined at run time */
@ -88,7 +87,7 @@ struct tblentry {
int special; /* flag for special builtin commands */
short cmdtype; /* index identifying command */
char rehash; /* if set, cd done since entry created */
char cmdname[ARB]; /* name of command */
char cmdname[]; /* name of command */
};
@ -563,7 +562,7 @@ cmdlookup(const char *name, int add)
}
if (add && cmdp == NULL) {
INTOFF;
cmdp = *pp = ckmalloc(sizeof (struct tblentry) - ARB
cmdp = *pp = ckmalloc(sizeof (struct tblentry)
+ strlen(name) + 1);
cmdp->next = NULL;
cmdp->cmdtype = CMDUNKNOWN;