Getaddrinfo() on glibc calls getenv(), oh boy

In the vast Unix environment, there are numerous traps that catch people off-guard, and one of the most notorious ones is the lack of thread safety. Specifically, when it comes to using the environment manipulation functions under glibc, caution must be exercised. It is well-known that calling setenv while running multiple threads can lead to a risk of segmentation fault if someone else simultaneously calls getenv. Surprisingly, this issue is not only limited to C or C++ languages but has even emerged in Go! Previously, I warned about the pitfalls of using mktime, which calls getenv, and now we have another culprit – getaddrinfo, which also relies on getenv. This fact may come as news to many, but it is essential to be aware of it. To connect to anything beyond legacy IPv4, getaddrinfo is indispensable, so it’s highly likely that you will encounter it frequently when dealing with the IPv6 Internet. If you are on Linux and using glibc, you are likely to face this challenge. It’s crucial to be informed and avoid any further complications. Many thanks to Evan for bringing this to our attention. Good luck with addressing this issue!

https://rachelbythebay.com/w/2023/10/16/env/

To top