random(6): Fix double-close
authorcem <cem@FreeBSD.org>
Wed, 11 May 2016 22:04:28 +0000 (22:04 +0000)
committercem <cem@FreeBSD.org>
Wed, 11 May 2016 22:04:28 +0000 (22:04 +0000)
commite002a9eee241d514f247c8c7f65964e042854473
treef38d90af23cd10217694b63ab93eb74b0a14f815
parent7c4ffc6797881e3a4501e7f7140277868c469aa0
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.

Reported by: Coverity
CID: 1006123
Sponsored by: EMC / Isilon Storage Division
usr.bin/random/randomize_fd.c