Resolves: RHEL-108555,RHEL-108568,RHEL-108576,RHEL-108584,RHEL-108596,RHEL-108598,RHEL-109096,RHEL-109488,RHEL-111065,RHEL-31756,RHEL-50103
51 lines
1.8 KiB
Diff
51 lines
1.8 KiB
Diff
From 50a7d58a24a381e265436c14303e7bb368a4b147 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 14 Feb 2023 03:41:26 +0900
|
|
Subject: [PATCH] time-util: do not use strdupa()
|
|
|
|
The input string may come from command line, config files.
|
|
|
|
(cherry picked from commit 804537bdc420bb82e54b455b7a10d542c8f029dd)
|
|
|
|
Related: RHEL-109488
|
|
---
|
|
src/basic/time-util.c | 16 ++++++++++++----
|
|
1 file changed, 12 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
|
|
index c5b91fde66..64cdcea594 100644
|
|
--- a/src/basic/time-util.c
|
|
+++ b/src/basic/time-util.c
|
|
@@ -681,9 +681,13 @@ static int parse_timestamp_impl(const char *t, usec_t *ret, bool with_tz) {
|
|
}
|
|
|
|
if ((k = endswith(t, " ago"))) {
|
|
- t = strndupa_safe(t, k - t);
|
|
+ _cleanup_free_ char *buf = NULL;
|
|
|
|
- r = parse_sec(t, &minus);
|
|
+ buf = strndup(t, k - t);
|
|
+ if (!buf)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ r = parse_sec(buf, &minus);
|
|
if (r < 0)
|
|
return r;
|
|
|
|
@@ -691,9 +695,13 @@ static int parse_timestamp_impl(const char *t, usec_t *ret, bool with_tz) {
|
|
}
|
|
|
|
if ((k = endswith(t, " left"))) {
|
|
- t = strndupa_safe(t, k - t);
|
|
+ _cleanup_free_ char *buf = NULL;
|
|
+
|
|
+ buf = strndup(t, k - t);
|
|
+ if (!buf)
|
|
+ return -ENOMEM;
|
|
|
|
- r = parse_sec(t, &plus);
|
|
+ r = parse_sec(buf, &plus);
|
|
if (r < 0)
|
|
return r;
|
|
|