Skip to content

Comments

Avoid calling setenv with identical previous contents.#27

Merged
alexcrichton merged 1 commit intorustls:masterfrom
Blub:avoid-unnecessary-setenv
Jan 23, 2025
Merged

Avoid calling setenv with identical previous contents.#27
alexcrichton merged 1 commit intorustls:masterfrom
Blub:avoid-unnecessary-setenv

Conversation

@Blub
Copy link
Contributor

@Blub Blub commented Oct 9, 2023

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: Perl/perl5#339
See-also: Perl/perl5#859
See-also: [1] Perl/perl5@916a038
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.

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: Perl/perl5#339
See-also: Perl/perl5#859
See-also: [1] Perl/perl5@916a038
See-also: [2] https://bugzilla.proxmox.com/show_bug.cgi?id=4979
Signed-off-by: Wolfgang Bumiller <[email protected]>
@alexcrichton
Copy link
Collaborator

I'm about a year and a half late to the punch but... hopefully better late the never? (sorry)

@alexcrichton alexcrichton merged commit 24c8855 into rustls:master Jan 23, 2025
@alexcrichton
Copy link
Collaborator

and thanks of course! (although I realize that's diluted taking >1 year to respond...)

@Blub
Copy link
Contributor Author

Blub commented Jan 23, 2025

We've just been patching it on our end and it's really just a workaround anyway.
I wish the libcs would just throw a mutex around env vars and declare raw access to the environ pointer "wrong" - wouldn't have helped us with perl, but not moving forward at all is also not great...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants