Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#8245 closed Bugs (fixed)

strerror is not thread-safe on all platforms

Reported by: Andrey Semashev Owned by: Steven Watanabe
Milestone: To Be Determined Component: random
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc:

Description

libs/random/src/random_device.cpp uses strerror function which is not thread-safe on many platforms (e.g. Linux). Its use should be replaced with strerror_r, when possible. Also, the way errno is used is not correct because it may be changed while the error string is composed.

The suggested solution would be to use system_error from Boost.System instead of invalid_argument. The possible errors don't look like are caused by an invalid argument anyway. The Boost.System implementation already uses strerror_r when possible, so the switch to system_error would resolve the problem.

Change History (8)

comment:1 by Andrey Semashev, 10 years ago

Component: Nonerandom
Owner: set to No-Maintainer

comment:2 by Andrey Semashev, 10 years ago

Owner: changed from No-Maintainer to Steven Watanabe

comment:3 by Steven Watanabe, 9 years ago

Resolution: fixed
Status: newclosed

comment:4 by Andrey Semashev, 9 years ago

Resolution: fixed
Status: closedreopened

The use of errno is still not fixed. It should be read once immediately at the beginning of error(const char * msg). Otherwise it may be clobbered by construction of other arguments to system_error constructor.

comment:6 by Steven Watanabe, 9 years ago

Resolution: fixed
Status: reopenedclosed

comment:7 by Andrey Semashev, 9 years ago

Steven, you closed the ticket but did not merge the pull request. Was this intentional? Are you rejecting the proposed fix?

comment:8 by Steven Watanabe, 9 years ago

Don't expect me to merge pull requests in general. Especially for things that are this simple, it's easier for me to type it in myself than to figure out the git commands I would need. I also generally make some changes when applying patches. In this case, the fix I applied is not quite the same as your pull request because I used the name error_code instead of err, to be consistent with the name in the Windows implementation.

Note: See TracTickets for help on using tickets.