]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r299484, r301574
authortruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 15 Jun 2016 06:27:43 +0000 (06:27 +0000)
committertruckman <truckman@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Wed, 15 Jun 2016 06:27:43 +0000 (06:27 +0000)
commit3f629d3134494288edf4965616408f90fae6f6d7
tree2d6932417f9daa445d960ce00db32c9ca43aa48a
parentd954d795a76309cc96340c830c116c48d708d246
MFC r299484, r301574

r299484 | cem | 2016-05-11 15:04:28 -0700 (Wed, 11 May 2016) | 13 lines

random(6): Fix double-close

In the case where a file lacks a trailing newline, there is some "evil" code to
reverse goto the tokenizing code ("make_token") for the final token in the
file.  In this case, 'fd' is closed more than once.  Use a negative sentinel
value to guard close(2), preventing the double close.

Ideally, this code would be restructured to avoid this ugly construction.

r301574 | truckman | 2016-06-07 19:14:05 -0700 (Tue, 07 Jun 2016) | 15 lines

Fix a (false positive?) Argument cannot be negative coverity defect.

Rather than guarding close(fd) with an fd >= 0 test and setting fd
to -1 when it is closed to avoid a potential double-close, just
move the close() call after the conditional "goto make_token".  This
moves the close() call totally outside the loop to avoid the
possibility of calling it twice.  This should also prevent a Coverity
warning about checking fd for validity after it was previously passed
to read().

Reported by: Coverity
CID: 10061231355335

git-svn-id: svn://svn.freebsd.org/base/stable/10@301917 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
games/random/randomize_fd.c