a9d0ee5451bcdbbf074c7ac56757fada4aa1f377
[openwrt/staging/noltari.git] / package / network / utils / nftables / patches / 0001-meta-don-t-use-non-POSIX-formats-in-strptime.patch
1 From 1af8aabccd65e11caa397c4706353075f623cd01 Mon Sep 17 00:00:00 2001
2 From: Jo-Philipp Wich <jo@mein.io>
3 Date: Mon, 8 Aug 2022 23:57:03 +0200
4 Subject: [PATCH] meta: don't use non-POSIX formats in strptime()
5
6 The current strptime() invocations in meta.c use the `%F` format which
7 is not specified by POSIX and thus unimplemented by some libc flavors
8 such as musl libc.
9
10 Replace all occurrences of `%F` with an equivalent `%Y-%m-%d` format
11 in order to be able to properly parse user supplied dates in such
12 environments.
13
14 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
15 ---
16 src/meta.c | 8 ++++----
17 1 file changed, 4 insertions(+), 4 deletions(-)
18
19 diff --git a/src/meta.c b/src/meta.c
20 index 80ace25b..257bbc9f 100644
21 --- a/src/meta.c
22 +++ b/src/meta.c
23 @@ -399,7 +399,7 @@ static void date_type_print(const struct expr *expr, struct output_ctx *octx)
24 tstamp += cur_tm->tm_gmtoff;
25
26 if ((tm = gmtime((time_t *) &tstamp)) != NULL &&
27 - strftime(timestr, sizeof(timestr) - 1, "%F %T", tm))
28 + strftime(timestr, sizeof(timestr) - 1, "%Y-%m-%d %T", tm))
29 nft_print(octx, "\"%s\"", timestr);
30 else
31 nft_print(octx, "Error converting timestamp to printed time");
32 @@ -412,11 +412,11 @@ static bool parse_iso_date(uint64_t *tstamp, const char *sym)
33
34 memset(&tm, 0, sizeof(struct tm));
35
36 - if (strptime(sym, "%F %T", &tm))
37 + if (strptime(sym, "%Y-%m-%d %T", &tm))
38 goto success;
39 - if (strptime(sym, "%F %R", &tm))
40 + if (strptime(sym, "%Y-%m-%d %R", &tm))
41 goto success;
42 - if (strptime(sym, "%F", &tm))
43 + if (strptime(sym, "%Y-%m-%d", &tm))
44 goto success;
45
46 return false;
47 --
48 2.35.1
49