[tor-commits] [torsocks/master] Fix: change socks5_send_ptr_request to use address type
dgoulet at torproject.org
dgoulet at torproject.org
Fri Apr 4 22:40:27 UTC 2014
commit 6c003efb7af3158b41396193de49621ea795007d
Author: Luke Gallagher <luke at hypergeometric.net>
Date: Mon Feb 17 10:08:00 2014 +1100
Fix: change socks5_send_ptr_request to use address type
inet_ntop returns a pointer to the destination string, so an IPv6
address would always be converted as if it were an IPv4 address
(AF_INET).
Add the address family as a third parameter to socks5_send_ptr_request
to reliably determine the address type to request. The order of
parameters to socks5_send_ptr_request has also been changed.
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/common/socks5.c | 12 +++++++-----
src/common/socks5.h | 2 +-
src/lib/torsocks.c | 2 +-
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/src/common/socks5.c b/src/common/socks5.c
index edf5c2e..fb0dc9c 100644
--- a/src/common/socks5.c
+++ b/src/common/socks5.c
@@ -585,11 +585,10 @@ error:
* Return 0 on success or else a negative value.
*/
ATTR_HIDDEN
-int socks5_send_resolve_ptr_request(const void *ip, struct connection *conn)
+int socks5_send_resolve_ptr_request(struct connection *conn, const void *ip, int af)
{
int ret, ret_send;
char buffer[20]; /* Can't go higher than that (with IPv6). */
- char ip_str[INET6_ADDRSTRLEN];
size_t msg_len, data_len;
struct socks5_request msg;
struct socks5_request_resolve_ptr req;
@@ -607,13 +606,16 @@ int socks5_send_resolve_ptr_request(const void *ip, struct connection *conn)
/* Always zeroed. */
msg.rsv = 0;
- if (inet_ntop(AF_INET, ip, ip_str, sizeof(ip_str))) {
+ switch (af) {
+ case AF_INET:
msg.atyp = SOCKS5_ATYP_IPV4;
memcpy(req.addr.ipv4, ip, 4);
- } else if (inet_ntop(AF_INET6, ip, ip_str, sizeof(ip_str))) {
+ break;
+ case AF_INET6:
msg.atyp = SOCKS5_ATYP_IPV6;
memcpy(req.addr.ipv6, ip, 16);
- } else {
+ break;
+ default:
ERR("Unknown address domain of %d", ip);
ret = -EINVAL;
goto error;
diff --git a/src/common/socks5.h b/src/common/socks5.h
index 2699357..67da3aa 100644
--- a/src/common/socks5.h
+++ b/src/common/socks5.h
@@ -133,6 +133,6 @@ int socks5_send_resolve_request(const char *hostname, struct connection *conn);
int socks5_recv_resolve_reply(struct connection *conn, void *addr,
size_t addrlent);
int socks5_recv_resolve_ptr_reply(struct connection *conn, char **_hostname);
-int socks5_send_resolve_ptr_request(const void *ip, struct connection *conn);
+int socks5_send_resolve_ptr_request(struct connection *conn, const void *ip, int af);
#endif /* TORSOCKS_SOCKS_H */
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c
index 4bbe072..ba7142d 100644
--- a/src/lib/torsocks.c
+++ b/src/lib/torsocks.c
@@ -454,7 +454,7 @@ int tsocks_tor_resolve_ptr(const char *addr, char **ip, int af)
goto end_close;
}
- ret = socks5_send_resolve_ptr_request(addr, &conn);
+ ret = socks5_send_resolve_ptr_request(&conn, addr, af);
if (ret < 0) {
goto end_close;
}
More information about the tor-commits
mailing list