]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r299484, r301574
authortruckman <truckman@FreeBSD.org>
Wed, 15 Jun 2016 06:27:43 +0000 (06:27 +0000)
committertruckman <truckman@FreeBSD.org>
Wed, 15 Jun 2016 06:27:43 +0000 (06:27 +0000)
commit6d64f4d6b9a42023c870cd90f9d20ce62b1e1694
tree2d6932417f9daa445d960ce00db32c9ca43aa48a
parentd7c7919b61f490e8f4a8fb07fbd6011d8005fdf5
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
games/random/randomize_fd.c