Use safer string functions
This commit is contained in:
parent
323a4d0147
commit
931b038b27
@ -669,7 +669,6 @@ BAD_REQUEST_ERROR:
|
|||||||
safefree (url);
|
safefree (url);
|
||||||
free_request_struct (request);
|
free_request_struct (request);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,7 +999,7 @@ write_via_header (int fd, hashmap_t hashofheaders,
|
|||||||
if (config.via_proxy_name) {
|
if (config.via_proxy_name) {
|
||||||
strlcpy (hostname, config.via_proxy_name, sizeof (hostname));
|
strlcpy (hostname, config.via_proxy_name, sizeof (hostname));
|
||||||
} else if (gethostname (hostname, sizeof (hostname)) < 0) {
|
} else if (gethostname (hostname, sizeof (hostname)) < 0) {
|
||||||
strcpy (hostname, "unknown");
|
strlcpy (hostname, "unknown", 512);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "html-error.h"
|
#include "html-error.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "reqs.h"
|
#include "reqs.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build a URL from parts.
|
* Build a URL from parts.
|
||||||
@ -59,6 +60,7 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
{
|
{
|
||||||
socklen_t length;
|
socklen_t length;
|
||||||
char *data;
|
char *data;
|
||||||
|
size_t ulen = strlen (url);
|
||||||
|
|
||||||
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
||||||
if (length <= 0) {
|
if (length <= 0) {
|
||||||
@ -75,11 +77,15 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
"url", url, NULL);
|
"url", url, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
request->host = (char *) safemalloc (17);
|
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->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);
|
safefree (url);
|
||||||
build_url (&url, request->host, request->port, request->path);
|
build_url (&url, request->host, request->port, request->path);
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
@ -89,11 +95,13 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
request->host = (char *) safemalloc (length + 1);
|
request->host = (char *) safemalloc (length + 1);
|
||||||
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
|
if (sscanf (data, "%[^:]:%hu", request->host, &request->port) !=
|
||||||
2) {
|
2) {
|
||||||
strcpy (request->host, data);
|
strlcpy (request->host, data, length + 1);
|
||||||
request->port = HTTP_PORT;
|
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);
|
safefree (url);
|
||||||
build_url (&url, request->host, request->port, request->path);
|
build_url (&url, request->host, request->port, request->path);
|
||||||
log_message (LOG_INFO,
|
log_message (LOG_INFO,
|
||||||
|
Loading…
Reference in New Issue
Block a user