#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 , 10 years ago
Component: | None → random |
---|---|
Owner: | set to |
comment:2 by , 10 years ago
Owner: | changed from | to
---|
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 9 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
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 , 9 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
comment:7 by , 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 , 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.
Fixed in http://github.com/boostorg/random/commit/dac48f62a8481560c2e8005bb6edcbfd409b3004.