]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: do not use strdupa()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 13 Feb 2023 18:41:26 +0000 (03:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Feb 2023 23:55:27 +0000 (08:55 +0900)
The input string may come from command line, config files.

src/basic/time-util.c

index 54624afda14815be1ecd94571500706819974f2d..15f908b137d5c869c1e92beceaa53187ac775420 100644 (file)
@@ -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;