1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

Fix bad setlocale usage.

This commit is contained in:
Micah Cowan 2009-06-11 18:58:26 -07:00
parent 5b42f5681f
commit 8477863e75
2 changed files with 17 additions and 1 deletions

View File

@ -1,5 +1,9 @@
2009-06-11 Micah Cowan <micah@cowan.name> 2009-06-11 Micah Cowan <micah@cowan.name>
* http.c (http_atotm): Handle potential for setlocale's return
value to be static storage. Thanks to Benjamin Wolsey
<bwy@benjaminwolsey.de>.
* sysdep.h: Need NAMESPACE_TWEAKS on non-Linux glibc-based * sysdep.h: Need NAMESPACE_TWEAKS on non-Linux glibc-based
systems, too. Thanks to Robert Millan. systems, too. Thanks to Robert Millan.

View File

@ -2935,6 +2935,7 @@ http_atotm (const char *time_string)
Netscape cookie specification.) */ Netscape cookie specification.) */
}; };
const char *oldlocale; const char *oldlocale;
char savedlocale[256];
size_t i; size_t i;
time_t ret = (time_t) -1; time_t ret = (time_t) -1;
@ -2942,6 +2943,16 @@ http_atotm (const char *time_string)
non-English locales, which we work around by temporarily setting non-English locales, which we work around by temporarily setting
locale to C before invoking strptime. */ locale to C before invoking strptime. */
oldlocale = setlocale (LC_TIME, NULL); oldlocale = setlocale (LC_TIME, NULL);
if (oldlocale)
{
size_t l = strlen (oldlocale);
if (l >= sizeof savedlocale)
savedlocale[0] = '\0';
else
memcpy (savedlocale, oldlocale, l);
}
else savedlocale[0] = '\0';
setlocale (LC_TIME, "C"); setlocale (LC_TIME, "C");
for (i = 0; i < countof (time_formats); i++) for (i = 0; i < countof (time_formats); i++)
@ -2961,7 +2972,8 @@ http_atotm (const char *time_string)
} }
/* Restore the previous locale. */ /* Restore the previous locale. */
setlocale (LC_TIME, oldlocale); if (savedlocale[0])
setlocale (LC_TIME, savedlocale);
return ret; return ret;
} }