From d4ecc4859e411c56e754cd1b467f14dd15d23ae1 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 8 Oct 2024 13:50:02 +0900
Subject: [PATCH 0930/1160] time-util: copy input string before fork()
Fixes #34670.
(cherry picked from commit 6d3012bab4ce4c1ed260598d05b4e9f2ea471658)
(cherry picked from commit 38d55448b9a56e406b00514303617249f30ee2f2)
src/basic/time-util.c | 8 ++++++++
1 file changed, 8 insertions(+)
@@ -1048,6 +1048,14 @@ int parse_timestamp(const char *t, usec_t *ret) {
if (shared == MAP_FAILED)
return negative_errno();
+ /* The input string may be in argv. Let's copy it. */
+ _cleanup_free_ char *t_copy = strdup(t);
+ if (!t_copy)
+ return -ENOMEM;
+
+ t = t_copy;
+ assert_se(tz = endswith(t_copy, tz));
+
r = safe_fork("(sd-timestamp)", FORK_RESET_SIGNALS|FORK_CLOSE_ALL_FDS|FORK_DEATHSIG_SIGKILL|FORK_WAIT, NULL);
if (r < 0) {
(void) munmap(shared, sizeof *shared);
--
2.33.0