Do not silently truncate URIs in evhttp_uri_join. Also avoid evbuffer_pullup.

This commit is contained in:
Nick Mathewson 2010-10-18 14:38:48 -04:00
parent 86212341c5
commit 7d45431e15
2 changed files with 8 additions and 9 deletions

15
http.c
View File

@ -3437,10 +3437,9 @@ void evhttp_uri_free(struct evhttp_uri *uri)
}
char *
evhttp_uri_join(struct evhttp_uri *uri, void *buf, size_t limit)
evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit)
{
struct evbuffer *tmp = 0;
unsigned char *joined = 0;
size_t joined_size = 0;
#define _URI_ADD(f) evbuffer_add(tmp, uri->f, strlen(uri->f))
@ -3482,15 +3481,15 @@ evhttp_uri_join(struct evhttp_uri *uri, void *buf, size_t limit)
evbuffer_add(tmp, "\0", 1); /* NUL */
joined = evbuffer_pullup(tmp, -1);
joined_size = evbuffer_get_length(tmp);
if (joined_size < limit)
memcpy(buf, joined, joined_size);
else {
memcpy(buf, joined, limit-1);
*((char *)buf+ limit - 1) = '\0';
if (joined_size > limit) {
/* It doesn't fit. */
evbuffer_free(tmp);
return NULL;
}
evbuffer_remove(tmp, buf, joined_size);
evbuffer_free(tmp);
return (char *)buf;

View File

@ -637,7 +637,7 @@ void evhttp_uri_free(struct evhttp_uri *uri);
* @return an joined uri as string or NULL on error
@see evhttp_uri_parse()
*/
char *evhttp_uri_join(struct evhttp_uri *uri, void *buf, size_t limit);
char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit);
#ifdef __cplusplus
}