From 4b00039e75e26ab0b85131d474e0e0ef85af9573 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 1 Dec 2020 07:34:20 -0700 Subject: 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. --- util.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'util.c') 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; -- cgit v1.2.1