From e780222ea72ed475a30db8ed452c76c38b23fdd1 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Thu, 5 Oct 2023 11:03:23 +0200 Subject: [PATCH] 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 --- perlmod/src/ffi.rs | 8 ++++++++ perlmod/src/glue.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/perlmod/src/ffi.rs b/perlmod/src/ffi.rs index 9f07bfa..b1ac2e7 100644 --- a/perlmod/src/ffi.rs +++ b/perlmod/src/ffi.rs @@ -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 _) } +} diff --git a/perlmod/src/glue.c b/perlmod/src/glue.c index 96f0618..6e05684 100644 --- a/perlmod/src/glue.c +++ b/perlmod/src/glue.c @@ -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