summaryrefslogtreecommitdiff
path: root/perl.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-03-06 14:18:45 -0700
committerKarl Williamson <khw@cpan.org>2020-03-11 09:52:12 -0600
commit24f3e849b5ce9f3bf6b6be5d3e730562e927aa79 (patch)
tree2aeee9a5124aea2f9617971dc2f3421fd8a0e858 /perl.c
parent2bc5f86adf5f1c0feb76d83e1a627e5649e6beab (diff)
downloadperl-24f3e849b5ce9f3bf6b6be5d3e730562e927aa79.tar.gz
Add thread safety to some environment accesses
The previous commit added a mutex specifically for protecting against simultaneous accesses of the environment. This commit changes the normal getenv, putenv, and clearenv functions to use it, to avoid races. This makes the code simpler in places where we've gotten burned and added stuff to avoid races. Other places where we haven't known we were getting burned could have existed until now. Now that comes automatically, and we can remove the special cases we earlier stumbled over. getenv() returns a pointer to static memory, which can be overwritten at any moment from another thread, or even another getenv from the same thread. This commit changes the accesses to be under control of a mutex, and in the case of getenv, a mortalized copy is created so that there is no possible race.
Diffstat (limited to 'perl.c')
-rw-r--r--perl.c4
1 files changed, 0 insertions, 4 deletions
diff --git a/perl.c b/perl.c
index dc555fbc95..df672f5fdf 100644
--- a/perl.c
+++ b/perl.c
@@ -2283,10 +2283,6 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
#endif
(s = PerlEnv_getenv("PERL5OPT")))
{
- /* s points to static memory in getenv(), which may be overwritten at
- * any time; use a mortal copy instead */
- s = SvPVX(sv_2mortal(newSVpv(s, 0)));
-
while (isSPACE(*s))
s++;
if (*s == '-' && *(s+1) == 'T') {