summaryrefslogtreecommitdiffhomepage
path: root/src/transparent-proxy.c
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@banu.com>2009-10-02 15:21:42 +0530
committerMukund Sivaraman <muks@banu.com>2009-10-02 15:21:42 +0530
commit931b038b27b4101d9c492443fbb05c4a88265f65 (patch)
tree95bab78b84965e37b0c31d3108823852f5734f8c /src/transparent-proxy.c
parent323a4d01478374cdacc0d4629fe1cc54f7513698 (diff)
Use safer string functions
Diffstat (limited to 'src/transparent-proxy.c')
-rw-r--r--src/transparent-proxy.c20
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,