Skip to content

Commit 24c8855

Browse files
authored
Merge pull request #27 from Blub/avoid-unnecessary-setenv
Avoid calling setenv with identical previous contents.
2 parents db67c9e + 4e93124 commit 24c8855

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,19 @@ pub fn try_init_ssl_cert_env_vars() -> bool {
6767
// we won't be overwriting existing env variables because if they're valid probe() will have
6868
// returned them unchanged
6969
if let Some(path) = &cert_file {
70-
env::set_var(ENV_CERT_FILE, path);
70+
put(ENV_CERT_FILE, path);
7171
}
7272
if let Some(path) = &cert_dir {
73-
env::set_var(ENV_CERT_DIR, path);
73+
put(ENV_CERT_DIR, path);
74+
}
75+
76+
fn put(var: &str, path: &Path) {
77+
// Avoid calling `setenv` if the variable already has the same contents. This avoids a
78+
// crash when called from out of perl <5.38 (Debian Bookworm is at 5.36), as old versions
79+
// of perl tend to manipulate the `environ` pointer directly.
80+
if env::var_os(var).as_deref() != Some(path.as_os_str()) {
81+
env::set_var(var, path);
82+
}
7483
}
7584

7685
cert_file.is_some() || cert_dir.is_some()

0 commit comments

Comments
 (0)