From c8aee09a93d0340c92f981e1556321cb10b4f935 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 24 Jan 2016 14:54:38 +0100 Subject: [PATCH] Native fixed/simplified DNS compression --- app/app.iml | 1 + app/src/main/jni/netguard/netguard.c | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/app.iml b/app/app.iml index 6e13ec56..c8002dfb 100644 --- a/app/app.iml +++ b/app/app.iml @@ -98,6 +98,7 @@ + diff --git a/app/src/main/jni/netguard/netguard.c b/app/src/main/jni/netguard/netguard.c index ca813067..3b7ede2a 100644 --- a/app/src/main/jni/netguard/netguard.c +++ b/app/src/main/jni/netguard/netguard.c @@ -1105,25 +1105,22 @@ int check_dns(const struct arguments *args, const struct udp_session *u, // http://tools.ietf.org/html/rfc1035 uint8_t len; - size_t ptr; size_t qdoff = dataoff + sizeof(struct dns_header); do { len = *(buffer + qdoff); - if (len <= 0x3F) { - ptr = qdoff; - qdoff += (1 + len); - } else { + if (len >= 0x40) { + // TODO test // TODO check top 2 bits - ptr = dataoff + (len & 0x3F) * 256 + *(buffer + qdoff + 1); - len = *(buffer + ptr); - qdoff += 2; + qdoff = dataoff + (len & 0x3F) * 256 + *(buffer + qdoff + 1); + len = *(buffer + qdoff); } - if (len && ptr + 1 + len <= dataoff + datalen) { - memcpy(name + noff, buffer + ptr + 1, len); + if (len && qdoff + 1 + len <= dataoff + datalen) { + memcpy(name + noff, buffer + qdoff + 1, len); *(name + noff + len) = '.'; noff += (len + 1); + qdoff += (1 + len); } - } while (len && ptr + 1 + len <= dataoff + datalen); + } while (len && qdoff + 1 + len <= dataoff + datalen); if (noff > 0 && qdoff + 4 <= dataoff + datalen) { *(name + noff - 1) = 0; @@ -1131,6 +1128,8 @@ int check_dns(const struct arguments *args, const struct udp_session *u, uint16_t qclass = ntohs(*((uint16_t *) (buffer + qdoff + 2))); qdoff += 4; + log_android(ANDROID_LOG_INFO, "DNS type %d class %d name %s", qtype, qclass, name); + if (qtype == DNS_QTYPE_A && qclass == DNS_QCLASS_IN) for (int i = 0; i < args->hcount; i++) if (!strcmp(name, args->hosts[i])) {