diff options
author | Omar Polo <op@omarpolo.com> | 2024-06-17 20:47:24 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-06-17 20:47:24 +0000 |
commit | acbe7a53131d0ba42bf919ea7a11dc7d1b60fb9c (patch) | |
tree | 58cc80505ca939bdcfef259d7b17a93d2f245745 | |
parent | 3db5bc7ccbc3fea3868a31926a338d7909220bba (diff) |
fix proxy_proto_v1_string
pass to inet_pton the full length of the buffer we're printing to.
It'll take care of NUL-terminating the string. If we subtract one it
may fail to print some IPv6 addresses. Also, no need to NUL-terminate
it again!
-rw-r--r-- | proxy-proto.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/proxy-proto.c b/proxy-proto.c index e90c851..43b9cae 100644 --- a/proxy-proto.c +++ b/proxy-proto.c @@ -187,17 +187,15 @@ proxy_proto_v1_string(const struct proxy_protocol_v1 *s, char* buf, size_t bufle { case PROTO_UNKNOWN: ret = snprintf(buf, buflen, "unknown"); goto fin; case PROTO_V4: { - inet_ntop(AF_INET, &s->srcaddr.v4, srcaddrbuf, 39); - inet_ntop(AF_INET, &s->dstaddr.v4, dstaddrbuf, 39); + inet_ntop(AF_INET, &s->srcaddr.v4, srcaddrbuf, sizeof(srcaddrbuf)); + inet_ntop(AF_INET, &s->dstaddr.v4, dstaddrbuf, sizeof(dstaddrbuf)); } break; case PROTO_V6: { - inet_ntop(AF_INET6, &s->srcaddr.v6, srcaddrbuf, 39); - inet_ntop(AF_INET6, &s->dstaddr.v6, dstaddrbuf, 39); + inet_ntop(AF_INET6, &s->srcaddr.v6, srcaddrbuf, sizeof(srcaddrbuf)); + inet_ntop(AF_INET6, &s->dstaddr.v6, dstaddrbuf, sizeof(dstaddrbuf)); } break; } - srcaddrbuf[39] = dstaddrbuf[39] = '\0'; - ret = snprintf( buf, buflen, |