summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2012-11-03 22:23:08 +0000
committerjilles <jilles@FreeBSD.org>2012-11-03 22:23:08 +0000
commitabfb4133f0f4a270aac26954a7db140b3f7b8646 (patch)
treece5dea03ee6757d8392afd4938c3450015c01c80 /bin
parente77bf633a0b379566f2c9ad79dc776ed4c716f54 (diff)
downloadFreeBSD-src-abfb4133f0f4a270aac26954a7db140b3f7b8646.zip
FreeBSD-src-abfb4133f0f4a270aac26954a7db140b3f7b8646.tar.gz
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.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/exec.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/bin/sh/exec.c b/bin/sh/exec.c
index cd49589..7ebf450 100644
--- a/bin/sh/exec.c
+++ b/bin/sh/exec.c
@@ -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;
OpenPOWER on IntegriCloud