From 39cad1bbbef547018ce231d307fcaab08c0aca28 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 24 Dec 2013 02:24:30 +0100 Subject: Fix invalid memory accesses after failed resolves --- src/fastd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/fastd.c b/src/fastd.c index c03a730..10fd0a3 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -407,8 +407,17 @@ static inline void update_time(fastd_context_t *ctx) { clock_gettime(CLOCK_MONOTONIC, &ctx->now); } +static inline void no_valid_address_debug(fastd_context_t *ctx, const fastd_peer_t *peer) { + pr_debug(ctx, "not sending a handshake to %P (no valid address resolved)", peer); +} + static void send_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { if (!fastd_peer_is_established(peer)) { + if (!peer->next_remote->n_addresses) { + no_valid_address_debug(ctx, peer); + return; + } + fastd_peer_claim_address(ctx, peer, NULL, NULL, &peer->next_remote->addresses[peer->next_remote->current_address]); fastd_peer_reset_socket(ctx, peer); } @@ -417,7 +426,7 @@ static void send_handshake(fastd_context_t *ctx, fastd_peer_t *peer) { return; if (peer->address.sa.sa_family == AF_UNSPEC) { - pr_debug(ctx, "not sending a handshake to %P (no valid address resolved)", peer); + no_valid_address_debug(ctx, peer); return; } -- cgit v1.2.3