mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 13:13:44 +01:00
Define and use TOR_ADDRPORT_BUF_LEN
This commit is contained in:
parent
c76f310fe7
commit
0daa1da3ba
5
changes/ticket33956
Normal file
5
changes/ticket33956
Normal file
@ -0,0 +1,5 @@
|
||||
o Code simplification and refactoring:
|
||||
- Define and use a new constant TOR_ADDRPORT_BUF_LEN which is like
|
||||
TOR_ADDR_BUF_LEN but includes enough space for an IP address,
|
||||
brackets, seperating colon, and port number. Closes ticket 33956.
|
||||
Patch by Neel Chauhan.
|
@ -564,10 +564,7 @@ channel_tls_get_transport_name_method(channel_t *chan, char **transport_out)
|
||||
static const char *
|
||||
channel_tls_get_remote_descr_method(channel_t *chan, int flags)
|
||||
{
|
||||
/* IPv6 address, colon, port */
|
||||
#define MAX_DESCR_LEN (TOR_ADDR_BUF_LEN + 1 + 5)
|
||||
|
||||
static char buf[MAX_DESCR_LEN + 1];
|
||||
static char buf[TOR_ADDRPORT_BUF_LEN];
|
||||
channel_tls_t *tlschan = BASE_CHAN_TO_TLS(chan);
|
||||
connection_t *conn;
|
||||
const char *answer = NULL;
|
||||
@ -580,15 +577,14 @@ channel_tls_get_remote_descr_method(channel_t *chan, int flags)
|
||||
switch (flags) {
|
||||
case 0:
|
||||
/* Canonical address with port*/
|
||||
tor_snprintf(buf, MAX_DESCR_LEN + 1,
|
||||
tor_snprintf(buf, TOR_ADDRPORT_BUF_LEN,
|
||||
"%s:%u", conn->address, conn->port);
|
||||
answer = buf;
|
||||
break;
|
||||
case GRD_FLAG_ORIGINAL:
|
||||
/* Actual address with port */
|
||||
addr_str = tor_addr_to_str_dup(&(tlschan->conn->real_addr));
|
||||
tor_snprintf(buf, MAX_DESCR_LEN + 1,
|
||||
"%s:%u", addr_str, conn->port);
|
||||
tor_snprintf(buf, TOR_ADDRPORT_BUF_LEN, "%s:%u", addr_str, conn->port);
|
||||
tor_free(addr_str);
|
||||
answer = buf;
|
||||
break;
|
||||
|
@ -1188,8 +1188,7 @@ fmt_addr_impl(const tor_addr_t *addr, int decorate)
|
||||
const char *
|
||||
fmt_addrport(const tor_addr_t *addr, uint16_t port)
|
||||
{
|
||||
/* Add space for a colon and up to 5 digits. */
|
||||
static char buf[TOR_ADDR_BUF_LEN + 6];
|
||||
static char buf[TOR_ADDRPORT_BUF_LEN];
|
||||
tor_snprintf(buf, sizeof(buf), "%s:%u", fmt_and_decorate_addr(addr), port);
|
||||
return buf;
|
||||
}
|
||||
|
@ -213,6 +213,15 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u)
|
||||
*/
|
||||
#define TOR_ADDR_BUF_LEN 48
|
||||
|
||||
/** Length of a buffer containing an IP address along with a port number and
|
||||
* a seperating colon.
|
||||
*
|
||||
* This allows enough space for
|
||||
* "[ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255]:12345",
|
||||
* plus a terminating NUL.
|
||||
*/
|
||||
#define TOR_ADDRPORT_BUF_LEN (TOR_ADDR_BUF_LEN + 6)
|
||||
|
||||
char *tor_addr_to_str_dup(const tor_addr_t *addr) ATTR_MALLOC;
|
||||
|
||||
/** Wrapper function of fmt_addr_impl(). It does not decorate IPv6
|
||||
|
Loading…
Reference in New Issue
Block a user