]> granicus.if.org Git - libevent/commitdiff
Do not silently truncate URIs in evhttp_uri_join. Also avoid evbuffer_pullup.
authorNick Mathewson <nickm@torproject.org>
Mon, 18 Oct 2010 18:38:48 +0000 (14:38 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 18 Oct 2010 18:38:48 +0000 (14:38 -0400)
http.c
include/event2/http.h

diff --git a/http.c b/http.c
index 7677e493e1d83c53a259ffbcb74a110705cdb70d..ba2d528b9b1d18886262dd0c09c697f5ec97474b 100644 (file)
--- a/http.c
+++ b/http.c
@@ -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;
index 9293270d17f7fe7c0b738c52ee7d1b9de89df04d..655ff254946e6465d0d4457412429a1885e532d2 100644 (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
 }