From a2d1ffa150491ad389a54cbd27ad56ed9dbe3cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Thu, 23 Jul 2020 20:22:38 +0200 Subject: [PATCH] fix #38: responds to NS/A with IP from -n argument As described in issue #38, DNS type NS requests to iodined got responses with additional IP that was incorrect (always 2.0.0.0) if the -n argument switch was used to specify a custom IP address. The same applied to A requests (for ns.topdomain); the IP was always 2.0.0.0 because of wrong memory copying. This commit fix solves this issue by correctly memory copying ns_ip to query destination (&q->destination). --- src/iodined.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/iodined.c b/src/iodined.c index 647892d..adafdfc 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -1548,8 +1548,9 @@ handle_ns_request(int dns_fd, struct query *q) if (ns_ip != INADDR_ANY) { /* If ns_ip set, overwrite destination addr with it. * Destination addr will be sent as additional record (A, IN) */ - struct sockaddr_in *addr = (struct sockaddr_in *) &q->destination; - memcpy(&addr->sin_addr, &ns_ip, sizeof(ns_ip)); + struct sockaddr_in *addr = (struct sockaddr_in *) &q->destination; /* probably not needed */ + memcpy(&q->destination, &ns_ip, sizeof(ns_ip)); + memcpy(&addr->sin_addr, &ns_ip, sizeof(ns_ip)); /* probably not needed */ } len = dns_encode_ns_response(buf, sizeof(buf), q, topdomain); @@ -1582,8 +1583,9 @@ handle_a_request(int dns_fd, struct query *q, int fakeip) } else if (ns_ip != INADDR_ANY) { /* If ns_ip set, overwrite destination addr with it. * Destination addr will be sent as additional record (A, IN) */ - struct sockaddr_in *addr = (struct sockaddr_in *) &q->destination; - memcpy(&addr->sin_addr, &ns_ip, sizeof(ns_ip)); + struct sockaddr_in *addr = (struct sockaddr_in *) &q->destination; /* probably not needed */ + memcpy(&q->destination, &ns_ip, sizeof(ns_ip)); + memcpy(&addr->sin_addr, &ns_ip, sizeof(ns_ip)); /* probably not needed */ } len = dns_encode_a_response(buf, sizeof(buf), q);