gettext-rs icon indicating copy to clipboard operation
gettext-rs copied to clipboard

gettext-rs is unsound as the `gettext` family is MT-Safe env

Open xerxes12354 opened this issue 4 years ago • 1 comments

I was looking at the time crate wondering why the time crate didn't give offsets, and I stumbled upon this thread on Internals. This seems like a big problem so I went looking for FFI crates where this could be a problem.

The gettext family of functions is MT-safe env, which means it can call getenv, it looks like this wrapper has a data race when set_env is called in another thread.

xerxes12354 avatar Apr 28 '21 22:04 xerxes12354

Thanks for reporting this! Unfortunately, FFI crates aren't the place to fix this; the underlying library calls (libc's getenv and setenv) give us no tools to avoid this unsafety, and since we don't control all the code within the process, we can't solve this with a lock either (as Kornel points out).

We could mark all our functions unsafe, and market gettext-rs as a set of "convenient wrappers" that translate the types, but I think that'll make the crate too hard to use in practice.

This is worth documenting though. I don't have energy for this right now, so please send a PR if you have a good phrasing in mind.

Minoru avatar Apr 29 '21 18:04 Minoru