transparent: fix invalid memory access
getsockname() requires addrlen to be set to the size of the sockaddr struct passed as the addr, and a check whether the returned addrlen exceeds the initially passed size (to determine whether the address returned is truncated). with a request like "GET /\r\n\r\n" where length is 0 this caused the code to assume success and use the values of the uninitialized sockaddr struct.
This commit is contained in:
parent
3230ce0bc2
commit
d98aabf47f
@ -65,10 +65,11 @@ do_transparent_proxy (struct conn_s *connptr, hashmap_t hashofheaders,
|
|||||||
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
length = hashmap_entry_by_key (hashofheaders, "host", (void **) &data);
|
||||||
if (length <= 0) {
|
if (length <= 0) {
|
||||||
struct sockaddr_in dest_addr;
|
struct sockaddr_in dest_addr;
|
||||||
|
length = sizeof(dest_addr);
|
||||||
|
|
||||||
if (getsockname
|
if (getsockname
|
||||||
(connptr->client_fd, (struct sockaddr *) &dest_addr,
|
(connptr->client_fd, (struct sockaddr *) &dest_addr,
|
||||||
&length) < 0) {
|
&length) < 0 || length > sizeof(dest_addr)) {
|
||||||
log_message (LOG_ERR,
|
log_message (LOG_ERR,
|
||||||
"process_request: cannot get destination IP for %d",
|
"process_request: cannot get destination IP for %d",
|
||||||
connptr->client_fd);
|
connptr->client_fd);
|
||||||
|
Loading…
Reference in New Issue
Block a user