diff options
Diffstat (limited to 'src/transparent-proxy.c')
-rw-r--r-- | src/transparent-proxy.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/transparent-proxy.c b/src/transparent-proxy.c index 96ae54b..907f51d 100644 --- a/src/transparent-proxy.c +++ b/src/transparent-proxy.c @@ -31,6 +31,7 @@ #include "html-error.h" #include "log.h" #include "reqs.h" +#include "text.h" /* * Build a URL from parts. @@ -59,6 +60,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders, { socklen_t length; char *data; + size_t ulen = strlen (url); length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data); if (length <= 0) { @@ -75,11 +77,15 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders, "url", url, NULL); return 0; } + request->host = (char *) safemalloc (17); - strcpy (request->host, inet_ntoa (dest_addr.sin_addr)); + strlcpy (request->host, inet_ntoa (dest_addr.sin_addr), 17); + request->port = ntohs (dest_addr.sin_port); - request->path = (char *) safemalloc (strlen (url) + 1); - strcpy (request->path, url); + + request->path = (char *) safemalloc (ulen + 1); + strlcpy (request->path, url, ulen + 1); + safefree (url); build_url (&url, request->host, request->port, request->path); log_message (LOG_INFO, @@ -89,11 +95,13 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders, request->host = (char *) safemalloc (length + 1); if (sscanf (data, "%[^:]:%hu", request->host, &request->port) != 2) { - strcpy (request->host, data); + strlcpy (request->host, data, length + 1); request->port = HTTP_PORT; } - request->path = (char *) safemalloc (strlen (url) + 1); - strcpy (request->path, url); + + request->path = (char *) safemalloc (ulen + 1); + strlcpy (request->path, url, ulen + 1); + safefree (url); build_url (&url, request->host, request->port, request->path); log_message (LOG_INFO, |