alexcrichton / openssl-probe

Apache License 2.0
54 stars 13 forks source link

Avoid calling setenv with identical previous contents. #27

Open Blub opened 11 months ago

Blub commented 11 months ago

As also stated in the stdlib documentation, setenv() is a bit of a dangerous interface and can cause a lot of headaches. For instance, perl before version 5.38 (at the time of writing, debian stable (bookworm) uses version 5.36) manipulates the environ pointer directly. When calling rust (or any other language) code from perl via bindings, calling setenv easily leads to crashes[2].

In perl 5.38 this was fixed [1] and perl should itself also stick to using setenv. This improves the situation a lot and leaves only the threading issue we cannot solve here.

This commit allows the perl code to preset the environment variables to avoid at least this instance of setenv causing crashes.

See-also: https://github.com/perl/perl5/issues/339 See-also: https://github.com/perl/perl5/issues/859 See-also: [1] https://github.com/Perl/perl5/pull/19514/commits/916a0387c5e9073acbb449f9ba081dfa05c77007 See-also: [2] https://bugzilla.proxmox.com/show_bug.cgi?id=4979

Note: ideally we could avoid the 2nd query to the env vars, but that would require a breaking change to ProbeResult to include where the values came from.