diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-12 16:11:45 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2026-02-12 16:11:45 +0100 |
| commit | 16f07314e675dd7d9d9cfb44dfb33cd81b13590d (patch) | |
| tree | 49f9cc94f4a41228d7ce400d731dc7280d21f79c | |
| parent | 45aae05ef642af248bb2ddf34568d8edfb779419 (diff) | |
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.
| -rw-r--r-- | http.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -6,6 +6,7 @@ #include <unistd.h> #include <errno.h> #include <inttypes.h> +#include <locale.h> #include <stdbool.h> #include <stddef.h> #include <stdlib.h> @@ -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, |
