]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r300547
authortruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 6 Jul 2016 17:45:38 +0000 (17:45 +0000)
committertruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 6 Jul 2016 17:45:38 +0000 (17:45 +0000)
commita0ec16e725b2e804aa2825eb23e9e1b32cc154d0
treeb8508db7b6ec491d1307c6f0630f0e57962c6183
parentc4e84a2562d787e53d526ea8d2fc875666d9e2a5
MFC r300547

Fix multiple Coverity Out-of-bounds access false postive issues in CAM

The currently used idiom for clearing the part of a ccb after its
header generates one or two Coverity errors for each time it is
used.  All instances generate an Out-of-bounds access (ARRAY_VS_SINGLETON)
error because of the treatment of the header as a two element array,
with a pointer to the non-existent second element being passed as
the starting address to bzero().  Some instances also alsp generate
Out-of-bounds access (OVERRUN) errors, probably because the space
being cleared is larger than the sizeofstruct ccb_hdr).

In addition, this idiom is difficult for humans to understand and
it is error prone.  The user has to chose the proper struct ccb_*
type (which does not appear in the surrounding code) for the sizeof()
in the length calculation.  I found several instances where the
length was incorrect, which could cause either an actual out of
bounds write, or incompletely clear the ccb.

A better way is to write the code to clear the ccb itself starting
at sizeof(ccb_hdr) bytes from the start of the ccb, and calculate
the length based on the specific type of struct ccb_* being cleared
as specified by the union ccb member being used.  The latter can
normally be seen in the nearby code.  This is friendlier for Coverity
and other static analysis tools because they will see that the
intent is to clear the trailing part of the ccb.

Wrap all of the boilerplate code in a convenient macro that only
requires a pointer to the desired union ccb member (or a pointer
to the union ccb itself) as an argument.

Reported by: Coverity
CID: 100757810086841009724100977310113041011306
CID: 101130710113081011309101131010113111011312
CID: 101131310113141011315101131610113171011318
CID: 101131910113201011321101132210113241011325
CID: 101132610113271011328101132910113301011374
CID: 101139010113911011392101139310113941011395
CID: 101139610113971011398101139910114001011401
CID: 101140210114031011404101140510114061011408
CID: 101140910114101011411101141210114131011414
CID: 101746110183871086860108687411942571229897
CID: 122996813062291306234133128213312831331294
CID: 133129513315351331536133153913315401341623
CID: 13416241341637134163813552641355324
Reviewed by: scottl, ken, delphij, imp
MFH: 1 month
Differential Revision: https://reviews.freebsd.org/D6496

git-svn-id: svn://svn.freebsd.org/base/stable/10@302377 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
lib/libcam/camlib.c
sbin/camcontrol/attrib.c
sbin/camcontrol/camcontrol.c
sbin/camcontrol/fwdownload.c
sbin/camcontrol/persist.c
sbin/iscontrol/fsm.c
sys/cam/cam_ccb.h
usr.sbin/camdd/camdd.c
usr.sbin/mptutil/mpt_cam.c