summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-12-01 07:34:20 -0700
committerKarl Williamson <khw@cpan.org>2022-09-29 13:08:27 -0600
commit4b00039e75e26ab0b85131d474e0e0ef85af9573 (patch)
treeacfdb23e5891b926e434fbe7a5457683ed05e5a0 /util.c
parentc7046d8a43482c8226fd9d241b6ff356e1bea540 (diff)
downloadperl-4b00039e75e26ab0b85131d474e0e0ef85af9573.tar.gz
perl.h: Finish implementing combo ENV/LOCALE mutexes
There are cases where an executing function is vulnerable to either the locale or environment being changed by another thread. This commit implements macros that use mutexes to protect these critical sections. There are two cases that exist: one where the functions only read; and one where they can also need exclusive control so that a competing thread can't overwrite the returned static buffer before it is safely copied. 5.32 had a placeholder for these, but didn't actually implement it. Instead it locked just the ENV portion. On modern platforms with thread-safe locales, the locale portion is a no-op anyway, so things worked on them. This new commit extends that safety to other platforms. This has long been a vulnerability in Perl.
Diffstat (limited to 'util.c')
-rw-r--r--util.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/util.c b/util.c
index a2403465e4..4ae3c9d6c1 100644
--- a/util.c
+++ b/util.c
@@ -3975,11 +3975,12 @@ Perl_init_tm(pTHX_ struct tm *ptm) /* see mktime, strftime and asctime */
PERL_UNUSED_CONTEXT;
PERL_ARGS_ASSERT_INIT_TM;
(void)time(&now);
- ENVr_LOCALEr_LOCK;
+
+ LOCALTIME_LOCK;
my_tm = localtime(&now);
if (my_tm)
Copy(my_tm, ptm, 1, struct tm);
- ENVr_LOCALEr_UNLOCK;
+ LOCALTIME_UNLOCK;
#else
PERL_UNUSED_CONTEXT;
PERL_ARGS_ASSERT_INIT_TM;