freebsd-skq/bin/sh
truckman d142cf7cea Hopefully fix Coverity CID 1008328 (Out-of-bounds write) in /bin/sh.
Replace the magic constant 127 in the loop interation count with
"PROMPTLEN - 1".

gethostname() is not guaranteed to NUL terminate the destination
string if it is too short. Decrease the length passed to gethostname()
by one, and add a NUL at the end of the buffer to make sure the
following loop to find the end of the name properly terminates.

The default: case is the likely cause of Coverity CID 1008328.  If
i is 126 at the top of the loop interation where the default case
is triggered, i will be incremented to 127 by the default case,
then incremented to 128 at the top of the loop before being compared
to 127 (PROMPTLENT - 1) and terminating the loop. Then the NUL
termination code after the loop will write to ps[128].  Fix by
checking for overflow before incrementing the index and storing the
second character in the buffer.

These fixes are not guaranteed to satisfy Coverity. The code that
increments i in the 'h'/'H' and 'w'/'W' cases may be beyond its
capability to analyze, but the code appears to be safe.

Reported by:	Coverity
CID:		1008328
Reviewed by:	jilles, cem
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6482
2016-05-23 01:01:23 +00:00
..
bltin
funcs
tests Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed 2016-05-04 23:20:53 +00:00
alias.c sh: Don't hash alias name when there are no aliases. 2016-02-21 20:58:24 +00:00
alias.h
arith_yacc.c
arith_yacc.h
arith_yylex.c
arith.h
builtins.def wordexp: Rewrite to make WRDE_NOCMD reliable. 2015-09-30 21:32:29 +00:00
cd.c sh: Remove a global variable from cd.c. 2016-01-24 17:01:34 +00:00
cd.h
error.c
error.h
eval.c sh: Update associated state when restoring locals while leaving a function. 2016-01-10 16:31:28 +00:00
eval.h sh: Make struct arglist an array instead of a linked list. 2015-10-11 21:33:00 +00:00
exec.c sh: Fix copying uninitialized field 'special'. 2016-03-13 22:54:14 +00:00
exec.h
expand.c sh: Fix some dead stores. 2016-03-06 17:24:02 +00:00
expand.h sh: Perform pathname generation during the first expansion phases. 2015-12-31 18:47:54 +00:00
histedit.c sh: Fix some dead stores. 2016-03-06 17:24:02 +00:00
input.c sh: Fix set -v and multiline history after r295825. 2016-02-23 22:44:01 +00:00
input.h
jobs.c MFH 2016-03-02 23:53:08 +00:00
jobs.h
mail.c
mail.h
main.c
main.h
Makefile DIRDEPS_BUILD: Run the staged bootstrap-tools version of build-tools. 2016-05-09 22:21:09 +00:00
Makefile.depend DIRDEPS_BUILD: Regenerate without local dependencies. 2016-02-24 17:20:11 +00:00
memalloc.c
memalloc.h
miscbltin.c sh(1): replace 0 with NULL for pointers. 2016-04-09 20:05:39 +00:00
mkbuiltins sh: Reduce size of builtins table. 2016-01-03 21:30:22 +00:00
mknodes.c sh/mknodes: Close files and check for errors when writing. 2015-12-20 16:40:36 +00:00
mksyntax.c
mktokens
myhistedit.h
mystring.c
mystring.h
nodes.c.pat sh: Remove global state from nodes.c. 2015-11-24 22:47:19 +00:00
nodetypes
options.c sh: Avoid out-of-bounds access in setoptionbyindex() for 'set -o nolog'. 2016-03-09 21:00:57 +00:00
options.h sh: Simplify some code related to positional parameters. 2016-01-19 22:41:26 +00:00
output.c
output.h
parser.c Hopefully fix Coverity CID 1008328 (Out-of-bounds write) in /bin/sh. 2016-05-23 01:01:23 +00:00
parser.h wordexp: Rewrite to make WRDE_NOCMD reliable. 2015-09-30 21:32:29 +00:00
redir.c sh: Don't allocate a redirtab if there are no redirections. 2016-01-30 21:21:25 +00:00
redir.h
sh.1 Fix handling of umtxp resource limit in sh(1)/ulimit(1), limits(1), add 2016-03-12 14:54:34 +00:00
shell.h
show.c
show.h
TOUR
trap.c sh: Fix use-after-free if a trap replaces itself. 2016-03-28 18:58:40 +00:00
trap.h
var.c sh: Clean a readonly local, even if the variable does not exist outside. 2016-01-22 20:10:08 +00:00
var.h sh: Make struct arglist an array instead of a linked list. 2015-10-11 21:33:00 +00:00