From 3dabff35b045357620740e0497b7c0445174057c Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 20 Jun 2012 13:38:37 +0300 Subject: dnsproxy: Check cache properly for TCP packets The DNS packet starts from offset 2 in TCP payload. --- src/dnsproxy.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/dnsproxy.c') diff --git a/src/dnsproxy.c b/src/dnsproxy.c index f309d0dd..d5c77f75 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -665,13 +665,22 @@ static uint16_t cache_check_validity(char *question, uint16_t type, return type; } -static struct cache_entry *cache_check(gpointer request, int *qtype) +static struct cache_entry *cache_check(gpointer request, int *qtype, int proto) { - char *question = request + 12; + char *question; struct cache_entry *entry; struct domain_question *q; uint16_t type; - int offset; + int offset, proto_offset; + + if (request == NULL) + return NULL; + + proto_offset = protocol_offset(proto); + if (proto_offset < 0) + return NULL; + + question = request + proto_offset + 12; offset = strlen(question) + 1; q = (void *) (question + offset); @@ -1457,7 +1466,7 @@ static int ns_resolv(struct server_data *server, struct request_data *req, char *dot, *lookup = (char *) name; struct cache_entry *entry; - entry = cache_check(request, &type); + entry = cache_check(request, &type, req->protocol); if (entry != NULL) { int ttl_left = 0; struct cache_data *data; -- cgit v1.2.3