BUG/MINOR threads: Use get_(local|gm)time instead of (local|gm)time
Using localtime / gmtime is not thread-safe, whereas the `get_*` wrappers are.
Found using GitHub's CodeQL scan.
The use in sample_conv_ltime() can be traced back to at least
fac9ccfb705702f211f99e67d5f5d5129002086a (first appearing in 1.6-dev3), so all
supported branches with thread support are affected.
diff --git a/src/sample.c b/src/sample.c
index 6f0ddee..b9d90ea 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -2300,18 +2300,16 @@
struct buffer *temp;
/* With high numbers, the date returned can be negative, the 55 bits mask prevent this. */
time_t curr_date = smp->data.u.sint & 0x007fffffffffffffLL;
- struct tm *tm;
+ struct tm tm;
/* add offset */
if (args[1].type == ARGT_SINT)
curr_date += args[1].data.sint;
- tm = localtime(&curr_date);
- if (!tm)
- return 0;
+ get_localtime(curr_date, &tm);
+
temp = get_trash_chunk();
- temp->data = strftime(temp->area, temp->size, args[0].data.str.area,
- tm);
+ temp->data = strftime(temp->area, temp->size, args[0].data.str.area, &tm);
smp->data.u.str = *temp;
smp->data.type = SMP_T_STR;
return 1;
@@ -2337,18 +2335,16 @@
struct buffer *temp;
/* With high numbers, the date returned can be negative, the 55 bits mask prevent this. */
time_t curr_date = smp->data.u.sint & 0x007fffffffffffffLL;
- struct tm *tm;
+ struct tm tm;
/* add offset */
if (args[1].type == ARGT_SINT)
curr_date += args[1].data.sint;
- tm = gmtime(&curr_date);
- if (!tm)
- return 0;
+ get_gmtime(curr_date, &tm);
+
temp = get_trash_chunk();
- temp->data = strftime(temp->area, temp->size, args[0].data.str.area,
- tm);
+ temp->data = strftime(temp->area, temp->size, args[0].data.str.area, &tm);
smp->data.u.str = *temp;
smp->data.type = SMP_T_STR;
return 1;