Skip to contentSkip to conversation

meta: don't use non-POSIX formats in strptime()

PATCH Applied Jo-Philipp Wich 2 participants 2 messages Aug 8, 2022 – Aug 9, 2022 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meta: don't use non-POSIX formats in strptime()

The current strptime() invocations in meta.c use the %F format which is not specified by POSIX and thus unimplemented by some libc flavors such as musl libc.

Replace all occurrences of %F with an equivalent %Y-%m-%d format in order to be able to properly parse user supplied dates in such environments.

---
 src/meta.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
src/meta.c +4 -4
index 80ace25b..257bbc9f 100644
@@ -399,7 +399,7 @@ static void date_type_print(const struct expr *expr, struct output_ctx *octx)
 		tstamp += cur_tm->tm_gmtoff;
 
 	if ((tm = gmtime((time_t *) &tstamp)) != NULL &&
-	     strftime(timestr, sizeof(timestr) - 1, "%F %T", tm))
+	     strftime(timestr, sizeof(timestr) - 1, "%Y-%m-%d %T", tm))
 		nft_print(octx, "\"%s\"", timestr);
 	else
 		nft_print(octx, "Error converting timestamp to printed time");
@@ -412,11 +412,11 @@ static bool parse_iso_date(uint64_t *tstamp, const char *sym)
 
 	memset(&tm, 0, sizeof(struct tm));
 
-	if (strptime(sym, "%F %T", &tm))
+	if (strptime(sym, "%Y-%m-%d %T", &tm))
 		goto success;
-	if (strptime(sym, "%F %R", &tm))
+	if (strptime(sym, "%Y-%m-%d %R", &tm))
 		goto success;
-	if (strptime(sym, "%F", &tm))
+	if (strptime(sym, "%Y-%m-%d", &tm))
 		goto success;
 
 	return false;
Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Jo-Philipp Wich

The current strptime() invocations in meta.c use the %F format which is not specified by POSIX and thus unimplemented by some libc flavors such as musl libc.

Replace all occurrences of %F with an equivalent %Y-%m-%d format in order to be able to properly parse user supplied dates in such environments.

Applied, thanks