/* Fixed size 29-byte string. Example: Sun, 06 Nov 1994 08:49:37 GMT */
char date_str[40]; /* using a bit larger buffer to paranoia reasons */
+ struct tm tm;
const char *responseString = "";
const char *infoString = NULL;
#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
* always fit into those kbytes.
*/
- strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime(&timer));
+ strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm));
+ /* ^^^ using gmtime_r() instead of gmtime() to not use static data */
len = sprintf(iobuf,
"HTTP/1.0 %d %s\r\n"
"Content-type: %s\r\n"
#endif
if (file_size != -1) { /* file */
- strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime(&last_mod));
+ strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&last_mod, &tm));
#if ENABLE_FEATURE_HTTPD_RANGES
if (responseNum == HTTP_PARTIAL_CONTENT) {
len += sprintf(iobuf + len,
/* NUL terminated */
static void fmt_time_human_30nul(char *s, char dt_delim)
{
+ struct tm tm;
struct tm *ptm;
struct timeval tv;
gettimeofday(&tv, NULL);
- ptm = gmtime(&tv.tv_sec);
+ ptm = gmtime_r(&tv.tv_sec, &tm);
+ /* ^^^ using gmtime_r() instead of gmtime() to not use static data */
sprintf(s, "%04u-%02u-%02u%c%02u:%02u:%02u.%06u000",
(unsigned)(1900 + ptm->tm_year),
(unsigned)(ptm->tm_mon + 1),