From: Yu Watanabe Date: Mon, 13 Feb 2023 18:41:26 +0000 (+0900) Subject: time-util: do not use strdupa() X-Git-Tag: v254-rc1~1163^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=804537bdc420bb82e54b455b7a10d542c8f029dd;p=thirdparty%2Fsystemd.git time-util: do not use strdupa() The input string may come from command line, config files. --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 54624afda14..15f908b137d 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -682,9 +682,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; @@ -692,9 +696,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;