From e89a5cc418ca7e00ef1d36393539b930942d5b92 Mon Sep 17 00:00:00 2001 From: Javier Steinaker Date: Fri, 9 Sep 2022 07:23:48 +1000 Subject: [PATCH] BHttpTime: cookie strings are in english, so strptime now uses POSIX (english) locale to parse them Change-Id: I863b59a3f3c27b656325752af7939576becf32f1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5629 Tested-by: Commit checker robot Reviewed-by: Adrien Destugues --- src/kits/network/libnetservices/HttpTime.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/kits/network/libnetservices/HttpTime.cpp b/src/kits/network/libnetservices/HttpTime.cpp index 11ee02d728..8ab42be535 100644 --- a/src/kits/network/libnetservices/HttpTime.cpp +++ b/src/kits/network/libnetservices/HttpTime.cpp @@ -12,6 +12,7 @@ #include #include +#include // The formats used should be, in order of preference (according to RFC2616, @@ -47,6 +48,8 @@ static const char* kDateFormats[] = { "%a %d %b %H:%M:%S %Y" }; +static locale_t posix = newlocale(LC_ALL_MASK, "POSIX", (locale_t)0); + #ifdef LIBNETAPI_DEPRECATED using namespace BPrivate; #else @@ -109,6 +112,10 @@ BHttpTime::Parse() memset(&expireTime, 0, sizeof(struct tm)); + // Save the current locale, switch to POSIX for strptime to match strings + // in English, switch back when we're done. + locale_t current = uselocale(posix); + fDateFormat = B_HTTP_TIME_FORMAT_PARSED; unsigned int i; for (i = 0; i < sizeof(kDateFormats) / sizeof(const char*); @@ -125,6 +132,8 @@ BHttpTime::Parse() } } + uselocale(current); + // Did we identify some valid format? if (fDateFormat == B_HTTP_TIME_FORMAT_PARSED) return 0;