Skip to content

Commit 3dc85d4

Browse files
Removing sprintf in favour of int2str
1 parent 69d2225 commit 3dc85d4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

modules/topology_hiding/thinfo_codec.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969

7070
#define LR_OUT_STR ";lr"
7171
#define R2_OUT_STR ";r2=on"
72-
#define MAX_PORT_OUT_LEN (sizeof(":65535") - 1)
7372

7473
static str lr_uri_param = str_init("lr");
7574
static str lr_on_uri_param = str_init("lr=on");
@@ -483,8 +482,13 @@ int thinfo_decode_socket(thinfo_encoded_t *thinfo, int *proto, str *ip, unsigned
483482
s += host.len; \
484483
if (domain_type == DOMAIN_IPV6) { CHECK_DECODE_BUF_BOUNDS(sizeof(char)); *s++ = ']'; } \
485484
if (port_val > 0) { \
486-
CHECK_DECODE_BUF_BOUNDS(MAX_PORT_OUT_LEN); \
487-
s += sprintf(s, ":%u", port_val); \
485+
int port_str_len = 0; \
486+
char *port_str = NULL; \
487+
port_str = int2str((uint64_t) port_val, &port_str_len); \
488+
CHECK_DECODE_BUF_BOUNDS(/* leading colon */ 1 + port_str_len); \
489+
*s++ = ':'; \
490+
memcpy(s, port_str, port_str_len); \
491+
s += port_str_len; \
488492
} \
489493
if (transport_val != TRANSPORT_UDP) { \
490494
if (transport_val < sizeof(TRANSPORT_STRINGS)/sizeof(TRANSPORT_STRINGS[0]) && \

0 commit comments

Comments
 (0)