r14508@tombo: nickm | 2008-02-26 15:24:01 -0500

Backport to 1.4 branch: Patch from Tani Hosokawa: make some functions in http.c threadsafe.  Also, note some functions in http.c that still are not threadsafe.


svn:r672
This commit is contained in:
Nick Mathewson 2008-02-26 20:24:52 +00:00
parent 134cbc86c4
commit aab6b84cc2
2 changed files with 11 additions and 9 deletions

View File

@ -1,5 +1,6 @@
Changes in 1.4.3-stable: Changes in 1.4.3-stable:
o include Content-Length in reply for HTTP/1.0 requests with keep-alive o include Content-Length in reply for HTTP/1.0 requests with keep-alive
o Patch from Tani Hosokawa: make some functions in http.c threadsafe.
Changes in 1.4.2-rc: Changes in 1.4.2-rc:
o remove pending timeouts on event_base_free() o remove pending timeouts on event_base_free()

19
http.c
View File

@ -188,10 +188,8 @@ strsep(char **s, const char *del)
#endif #endif
static const char * static const char *
html_replace(char ch) html_replace(char ch, char *buf)
{ {
static char buf[2];
switch (ch) { switch (ch) {
case '<': case '<':
return "&lt;"; return "&lt;";
@ -226,15 +224,16 @@ evhttp_htmlescape(const char *html)
{ {
int i, new_size = 0, old_size = strlen(html); int i, new_size = 0, old_size = strlen(html);
char *escaped_html, *p; char *escaped_html, *p;
char scratch_space[2];
for (i = 0; i < old_size; ++i) for (i = 0; i < old_size; ++i)
new_size += strlen(html_replace(html[i])); new_size += strlen(html_replace(html[i], scratch_space));
p = escaped_html = malloc(new_size + 1); p = escaped_html = malloc(new_size + 1);
if (escaped_html == NULL) if (escaped_html == NULL)
event_err(1, "%s: malloc(%d)", __func__, new_size + 1); event_err(1, "%s: malloc(%d)", __func__, new_size + 1);
for (i = 0; i < old_size; ++i) { for (i = 0; i < old_size; ++i) {
const char *replaced = html_replace(html[i]); const char *replaced = html_replace(html[i], scratch_space);
/* this is length checked */ /* this is length checked */
strcpy(p, replaced); strcpy(p, replaced);
p += strlen(replaced); p += strlen(replaced);
@ -308,7 +307,7 @@ static void
evhttp_make_header_request(struct evhttp_connection *evcon, evhttp_make_header_request(struct evhttp_connection *evcon,
struct evhttp_request *req) struct evhttp_request *req)
{ {
static char line[1024]; char line[1024];
const char *method; const char *method;
evhttp_remove_header(req->output_headers, "Accept-Encoding"); evhttp_remove_header(req->output_headers, "Accept-Encoding");
@ -380,7 +379,7 @@ evhttp_maybe_add_content_length_header(struct evkeyvalq *headers,
{ {
if (evhttp_find_header(headers, "Transfer-Encoding") == NULL && if (evhttp_find_header(headers, "Transfer-Encoding") == NULL &&
evhttp_find_header(headers, "Content-Length") == NULL) { evhttp_find_header(headers, "Content-Length") == NULL) {
static char len[12]; /* XXX: not thread-safe */ char len[12];
snprintf(len, sizeof(len), "%ld", content_length); snprintf(len, sizeof(len), "%ld", content_length);
evhttp_add_header(headers, "Content-Length", len); evhttp_add_header(headers, "Content-Length", len);
} }
@ -394,7 +393,7 @@ static void
evhttp_make_header_response(struct evhttp_connection *evcon, evhttp_make_header_response(struct evhttp_connection *evcon,
struct evhttp_request *req) struct evhttp_request *req)
{ {
static char line[1024]; char line[1024];
snprintf(line, sizeof(line), "HTTP/%d.%d %d %s\r\n", snprintf(line, sizeof(line), "HTTP/%d.%d %d %s\r\n",
req->major, req->minor, req->response_code, req->major, req->minor, req->response_code,
req->response_code_line); req->response_code_line);
@ -436,7 +435,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
void void
evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
{ {
static char line[1024]; char line[1024];
struct evkeyval *header; struct evkeyval *header;
/* /*
@ -470,6 +469,7 @@ evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
int int
evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile) evhttp_hostportfile(char *url, char **phost, u_short *pport, char **pfile)
{ {
/* XXX not threadsafe. */
static char host[1024]; static char host[1024];
static char file[1024]; static char file[1024];
char *p; char *p;
@ -2352,6 +2352,7 @@ name_from_addr(struct sockaddr *sa, socklen_t salen,
char **phost, char **pport) char **phost, char **pport)
{ {
#ifdef HAVE_GETNAMEINFO #ifdef HAVE_GETNAMEINFO
/* XXXX not threadsafe. */
static char ntop[NI_MAXHOST]; static char ntop[NI_MAXHOST];
static char strport[NI_MAXSERV]; static char strport[NI_MAXSERV];
int ni_result; int ni_result;