SF Bug Tracker id 3507819 - Use of thread-unsafe gmtime() in httpreadwrite.c
Define http_gmtime_r and web_server_asctime_r and use it. Those prefix are added since pthread for Win32 already has macro gmtime_r and asctime_r. (forward port of commit 34a77cc095a6be89a7cb2d71202364c3cc7e8d26)
This commit is contained in:
parent
85fd18ad64
commit
79d4b583fe
12
ChangeLog
12
ChangeLog
@ -332,7 +332,17 @@ Version 1.8.0
|
|||||||
Version 1.6.18
|
Version 1.6.18
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
|
|
||||||
2012-03-26 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
|
2012-04-05 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
|
||||||
|
|
||||||
|
SF Bug Tracker id 3507819 - Use of thread-unsafe gmtime() in httpreadwrite.c
|
||||||
|
|
||||||
|
Submitted: zephyrus ( zephyrus00jp ) - 2012-03-18 06:31:00 PDT
|
||||||
|
|
||||||
|
Define http_gmtime_r and web_server_asctime_r and use it.
|
||||||
|
Those prefix are added since pthread for Win32 already
|
||||||
|
has macro gmtime_r and asctime_r.
|
||||||
|
|
||||||
|
2012-04-05 Yoichi NAKAYAMA <yoichi.nakayama(at)gmail.com>
|
||||||
|
|
||||||
Fix type of local variable stopSock in RunMiniServer()
|
Fix type of local variable stopSock in RunMiniServer()
|
||||||
|
|
||||||
|
@ -164,6 +164,18 @@ static int private_connect(
|
|||||||
#endif /* UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS */
|
#endif /* UPNP_ENABLE_BLOCKING_TCP_CONNECTIONS */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
struct tm *http_gmtime_r(const time_t *clock, struct tm *result)
|
||||||
|
{
|
||||||
|
if (clock == NULL || *clock < 0 || result == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* gmtime in VC runtime is thread safe. */
|
||||||
|
*result = *gmtime(clock);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int get_hoststr(const char* url_str,
|
static int get_hoststr(const char* url_str,
|
||||||
char **hoststr,
|
char **hoststr,
|
||||||
size_t *hostlen)
|
size_t *hostlen)
|
||||||
@ -1466,6 +1478,7 @@ int http_MakeMessage(membuffer *buf, int http_major_version,
|
|||||||
size_t length;
|
size_t length;
|
||||||
time_t *loc_time;
|
time_t *loc_time;
|
||||||
time_t curr_time;
|
time_t curr_time;
|
||||||
|
struct tm date_storage;
|
||||||
struct tm *date;
|
struct tm *date;
|
||||||
const char *start_str;
|
const char *start_str;
|
||||||
const char *end_str;
|
const char *end_str;
|
||||||
@ -1553,7 +1566,7 @@ int http_MakeMessage(membuffer *buf, int http_major_version,
|
|||||||
loc_time = (time_t *)va_arg(argp, time_t *);
|
loc_time = (time_t *)va_arg(argp, time_t *);
|
||||||
}
|
}
|
||||||
assert(loc_time);
|
assert(loc_time);
|
||||||
date = gmtime(loc_time);
|
date = http_gmtime_r(loc_time, &date_storage);
|
||||||
if (date == NULL)
|
if (date == NULL)
|
||||||
goto error_handler;
|
goto error_handler;
|
||||||
rc = snprintf(tempbuf, sizeof(tempbuf),
|
rc = snprintf(tempbuf, sizeof(tempbuf),
|
||||||
|
@ -134,6 +134,20 @@ static const char *gMediaTypes[] = {
|
|||||||
#define NUM_MEDIA_TYPES 69
|
#define NUM_MEDIA_TYPES 69
|
||||||
#define NUM_HTTP_HEADER_NAMES 33
|
#define NUM_HTTP_HEADER_NAMES 33
|
||||||
|
|
||||||
|
#define ASCTIME_R_BUFFER_SIZE 26
|
||||||
|
#ifdef WIN32
|
||||||
|
static char *web_server_asctime_r(const struct tm *tm, char *buf)
|
||||||
|
{
|
||||||
|
if (tm == NULL || buf == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
asctime_s(buf, ASCTIME_R_BUFFER_SIZE, tm);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define web_server_asctime_r asctime_r
|
||||||
|
#endif
|
||||||
|
|
||||||
/* sorted by file extension; must have 'NUM_MEDIA_TYPES' extensions */
|
/* sorted by file extension; must have 'NUM_MEDIA_TYPES' extensions */
|
||||||
static const char *gEncodedMediaTypes =
|
static const char *gEncodedMediaTypes =
|
||||||
"aif\0" AUDIO_STR "aiff\0"
|
"aif\0" AUDIO_STR "aiff\0"
|
||||||
@ -515,6 +529,8 @@ static int get_file_info(
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
time_t aux_LastModified;
|
time_t aux_LastModified;
|
||||||
|
struct tm date;
|
||||||
|
char buffer[ASCTIME_R_BUFFER_SIZE];
|
||||||
|
|
||||||
UpnpFileInfo_set_ContentType(info, NULL);
|
UpnpFileInfo_set_ContentType(info, NULL);
|
||||||
code = stat(filename, &s);
|
code = stat(filename, &s);
|
||||||
@ -539,7 +555,7 @@ static int get_file_info(
|
|||||||
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
||||||
filename,
|
filename,
|
||||||
(long long)UpnpFileInfo_get_FileLength(info),
|
(long long)UpnpFileInfo_get_FileLength(info),
|
||||||
asctime(gmtime(&aux_LastModified)),
|
web_server_asctime_r(http_gmtime_r(&aux_LastModified, &date), buffer),
|
||||||
UpnpFileInfo_get_IsReadable(info));
|
UpnpFileInfo_get_IsReadable(info));
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -49,6 +49,12 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
struct tm *http_gmtime_r(const time_t *clock, struct tm *result);
|
||||||
|
#else
|
||||||
|
#define http_gmtime_r gmtime_r
|
||||||
|
#endif
|
||||||
|
|
||||||
int http_CancelHttpGet(IN void *Handle);
|
int http_CancelHttpGet(IN void *Handle);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user