diff options
author | jilles <jilles@FreeBSD.org> | 2012-11-03 22:23:08 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-11-03 22:23:08 +0000 |
commit | abfb4133f0f4a270aac26954a7db140b3f7b8646 (patch) | |
tree | ce5dea03ee6757d8392afd4938c3450015c01c80 /bin | |
parent | e77bf633a0b379566f2c9ad79dc776ed4c716f54 (diff) | |
download | FreeBSD-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.c | 5 |
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; |