]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r300442
authortruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 1 Jun 2016 17:09:50 +0000 (17:09 +0000)
committertruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 1 Jun 2016 17:09:50 +0000 (17:09 +0000)
commit53ce52fb7a46f0a8ff2a95da3577fe491f8ac2b3
tree5adc89fbc9b6f59ebe6264a1faeae0cacb880db4
parentcd39c8b7d8e4ae9927bff52a0f4b732976132b6b
MFC r300442

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
Differential Revision: https://reviews.freebsd.org/D6482

git-svn-id: svn://svn.freebsd.org/base/stable/10@301140 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
bin/sh/parser.c