From 16f07314e675dd7d9d9cfb44dfb33cd81b13590d Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 12 Feb 2026 16:11:45 +0100 Subject: http.c: Force POSIX locale on append_expire Otherwise, strftime(3) could return different strings depending on the system configuration, and therefore return 0 if the resulting string does not fit into buf. --- http.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index 098912b..0fcae07 100644 --- a/http.c +++ b/http.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -2750,11 +2751,18 @@ failure: static int append_expire(struct dynstr *const d, const struct tm *const exp) { + int ret = -1; char s[sizeof "Thu, 01 Jan 1970 00:00:00 GMT"]; + const locale_t l = newlocale(LC_TIME_MASK, "POSIX", (locale_t)0); - if (!strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S GMT", exp)) + if (l == (locale_t)0) { - fprintf(stderr, "%s: strftime(3) failed\n", __func__); + fprintf(stderr, "%s: newlocale(3): %s\n", __func__, strerror(errno)); + goto end; + } + else if (!strftime_l(s, sizeof s, "%a, %d %b %Y %H:%M:%S GMT", exp, l)) + { + fprintf(stderr, "%s: strftime_l(3) failed\n", __func__); return -1; } else if (dynstr_append(d, "; Expires=%s", s)) @@ -2763,7 +2771,11 @@ static int append_expire(struct dynstr *const d, const struct tm *const exp) return -1; } - return 0; + ret = 0; + +end: + freelocale(l); + return ret; } char *http_cookie_create(const char *const key, const char *const value, -- cgit v1.2.3