add ffi::use_safe_putenv and glue for it

This causes changes to environment variables to leak instead of crash,
which is arguably better. This will be removed (and fixed) in perl
5.38.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-10-05 11:03:23 +02:00
parent b425032d53
commit e780222ea7
2 changed files with 12 additions and 0 deletions

View File

@ -412,6 +412,8 @@ extern "C" {
pub fn RSPL_substr(orig: *mut SV, off: usize, len: usize) -> *mut SV;
pub fn RSPL_defstash() -> *mut HV;
pub fn RSPL_set_use_safe_putenv(on: libc::c_int);
}
/// Argument marker for the stack.
@ -577,3 +579,9 @@ where
res
}
/// Tell perl to use a "safe" `putenv` call instead of manually manipulating the `environ`
/// variable. Without this, changing environment variables can lead to crashes.
pub fn use_safe_putenv(on: bool) {
unsafe { RSPL_set_use_safe_putenv(on as _) }
}

View File

@ -454,6 +454,10 @@ extern HV* RSPL_defstash() {
return PL_defstash;
}
extern void RSPL_set_use_safe_putenv(int on) {
PL_use_safe_putenv = on ? TRUE : FALSE;
}
/*
These make are convoluted brainfarts:
SVt_NULL undef