Some uses of non-threadsafe strerror
have snuck into the code since they were removed in #4152. Add a wrapper SysErrorString
for thread-safe strerror alternatives (with code from NetworkErrorString
) and replace all uses of strerror
with this.
Edit: I’ve also added a commit that refactors the code so that buf[] is never read at all if the function fails, making some fragile-looking code unnecessary.
Edit2: from the linux manpage:
0ATTRIBUTES
1 For an explanation of the terms used in this section, see attributes(7).
2
3 ┌───────────────────┬───────────────┬─────────────────────────┐
4 │Interface │ Attribute │ Value │
5 ├───────────────────┼───────────────┼─────────────────────────┤
6 │strerror() │ Thread safety │ MT-Unsafe race:strerror │
7 ├───────────────────┼───────────────┼─────────────────────────┤
8…
9 ├───────────────────┼───────────────┼─────────────────────────┤
10 │strerror_r(), │ Thread safety │ MT-Safe │
11 │strerror_l() │ │ │
12 └───────────────────┴───────────────┴─────────────────────────┘
As the function can be called from any thread at any time, using a non-thread-safe function is unacceptable.