Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sh_setmatch: do not allocate a size 0 block (re: f38494e)
In init.c:867, calloc(3) may be called with a size of 0 on line 867 if nmatch is zero but v (value) is non-NULL. (This is currently triggered by the arrays.sh and attributes.sh regression tests.) As POSIX states: "If the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned, or the behavior shall be as if the size were some non-zero value, except that the behavior is undefined if the returned pointer is used to access an object."[*] Either way, the behaviour is undefined if the returned pointer is dereferenced. src/cmd/ksh93/sh/init.c: sh_set_match(): - Before calling calloc, return if either nmatch is 0 (there were no matches) or v is NULL (there is no value). Do not require both conditions to be true to return. [*] https://pubs.opengroup.org/onlinepubs/9799919799/functions/calloc.html
- Loading branch information