Skip to content

Commit

Permalink
don't access source_addr through io->app_data. keep addrinfo for sour…
Browse files Browse the repository at this point in the history
…ce address until bind is attempted (#770)
  • Loading branch information
scareything authored Dec 20, 2023
1 parent 48107a5 commit 9237bb5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ziti-tunnel-cbs/ziti_hosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static const char *compute_dst_port(const host_ctx_t *service, const tunneler_ap

static int do_bind(hosted_io_context io, const char *addr, int socktype) {
// split out the ip and port if port was specified
char *src_ip = strdup(io->app_data->source_addr);
char *src_ip = strdup(addr);
char *port = strchr(src_ip, ':');
if (port != NULL) {
*port = '\0';
Expand Down Expand Up @@ -419,8 +419,6 @@ static int do_bind(hosted_io_context io, const char *addr, int socktype) {

ziti_address src_za;
ziti_address_from_sockaddr(&src_za, ai_req.addrinfo->ai_addr); // convert for easy validation
uv_freeaddrinfo(ai_req.addrinfo);

if (!address_match(&src_za, &io->service->allowed_source_addresses)) {
ZITI_LOG(ERROR, "hosted_service[%s], client[%s] client requested source IP %s is not allowed",
io->service->service_name, io->client_identity, io->app_data->source_addr);
Expand All @@ -437,9 +435,11 @@ static int do_bind(hosted_io_context io, const char *addr, int socktype) {
default:
ZITI_LOG(ERROR, "hosted_service[%s] client[%s] unsupported protocol %d when binding source address",
io->service->service_name, io->client_identity, hints.ai_protocol);
return -1;
uv_err = UV_EINVAL;
}

uv_freeaddrinfo(ai_req.addrinfo);

if (uv_err != 0) {
ZITI_LOG(ERROR, "hosted_service[%s] client[%s]: bind failed: %s", io->service->service_name,
io->client_identity, uv_strerror(uv_err));
Expand Down

0 comments on commit 9237bb5

Please sign in to comment.