From 9015eb2c40ca51f1adfe24d17f169ce19cfab4c6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Wed, 26 Oct 2011 12:44:01 +0000 Subject: [PATCH] bugs --- src/vpn/gnunet-dns-parser.c | 25 +++++++++++++------------ src/vpn/gnunet-service-dns.c | 13 ++++++++++--- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c index 31b0af1a7..e3b03fefd 100644 --- a/src/vpn/gnunet-dns-parser.c +++ b/src/vpn/gnunet-dns-parser.c @@ -154,6 +154,7 @@ unparse_dns_name(char* dest, char* src, size_t len) cnt = 0; b = dest; dest++; + src++; } *b = 0; } @@ -163,36 +164,36 @@ unparse_dns_packet (struct dns_pkt_parsed* ppkt) { size_t size = sizeof(struct dns_pkt) - 1; int i; - for (i = 0; i < ppkt->s.qdcount; i++) + for (i = 0; i < ntohs(ppkt->s.qdcount); i++) size += ppkt->queries[i]->namelen + 1; - for (i = 0; i < ppkt->s.ancount; i++) + for (i = 0; i < ntohs(ppkt->s.ancount); i++) { size += ppkt->answers[i]->namelen + 1; size += ppkt->answers[i]->data_len; } - for (i = 0; i < ppkt->s.nscount; i++) + for (i = 0; i < ntohs(ppkt->s.nscount); i++) { size += ppkt->nameservers[i]->namelen + 1; size += ppkt->nameservers[i]->data_len; } - for (i = 0; i < ppkt->s.arcount; i++) + for (i = 0; i < ntohs(ppkt->s.arcount); i++) { size += ppkt->additional[i]->namelen + 1; size += ppkt->additional[i]->data_len; } - size += 4*ppkt->s.qdcount + 10*( - ppkt->s.ancount+ - ppkt->s.arcount+ - ppkt->s.nscount); + size += 4*ntohs(ppkt->s.qdcount) + 10*( + ntohs(ppkt->s.ancount)+ + ntohs(ppkt->s.arcount)+ + ntohs(ppkt->s.nscount)); struct dns_pkt *pkt = GNUNET_malloc(size); char *pkt_c = (char*)pkt; memcpy(&pkt->s, &ppkt->s, sizeof ppkt->s); size_t idx = sizeof ppkt->s; - for (i = 0; i < ppkt->s.qdcount; i++) + for (i = 0; i < ntohs(ppkt->s.qdcount); i++) { unparse_dns_name(&pkt_c[idx], ppkt->queries[i]->name, ppkt->queries[i]->namelen); idx += ppkt->queries[i]->namelen; @@ -202,7 +203,7 @@ unparse_dns_packet (struct dns_pkt_parsed* ppkt) idx += sizeof(struct dns_query_line); } - for (i = 0; i < ppkt->s.ancount; i++) + for (i = 0; i < ntohs(ppkt->s.ancount); i++) { unparse_dns_name(&pkt_c[idx], ppkt->answers[i]->name, ppkt->answers[i]->namelen); idx += ppkt->answers[i]->namelen; @@ -216,7 +217,7 @@ unparse_dns_packet (struct dns_pkt_parsed* ppkt) idx += ppkt->answers[i]->data_len; } - for (i = 0; i < ppkt->s.nscount; i++) + for (i = 0; i < ntohs(ppkt->s.nscount); i++) { unparse_dns_name(&pkt_c[idx], ppkt->nameservers[i]->name, ppkt->nameservers[i]->namelen); idx += ppkt->nameservers[i]->namelen; @@ -230,7 +231,7 @@ unparse_dns_packet (struct dns_pkt_parsed* ppkt) idx += ppkt->nameservers[i]->data_len; } - for (i = 0; i < ppkt->s.arcount; i++) + for (i = 0; i < ntohs(ppkt->s.arcount); i++) { unparse_dns_name(&pkt_c[idx], ppkt->additional[i]->name, ppkt->additional[i]->namelen); idx += ppkt->additional[i]->namelen; diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 2f413c763..00d93ab24 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -499,9 +499,12 @@ receive_mesh_answer (void *cls int i = 0; while (i < ntohs(pdns->s.ancount) && - pdns->answers[i]->type != 28 && - pdns->answers[i]->type != 1) + ntohs(pdns->answers[i]->type) != 28 && + ntohs(pdns->answers[i]->type) != 1) +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Answer contains %d.\n", ntohs(pdns->answers[i]->type)); i++; +} if (i >= ntohs (pdns->s.ancount)) { @@ -1005,14 +1008,18 @@ receive_query (void *cls cls_->hdr.size - sizeof (struct GNUNET_MessageHeader)); GNUNET_SCHEDULER_add_now (send_mesh_query, cls_); - if (pdns->s.qdcount == 1) + if (ntohs(pdns->s.qdcount) == 1) { if (ntohs(pdns->queries[0]->qtype) == 1) pdns->queries[0]->qtype = htons(28); else if (ntohs(pdns->queries[0]->qtype) == 28) pdns->queries[0]->qtype = htons(1); else +{ + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "not sending second packet\n"); goto outfree; +} + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "sending second packet\n"); struct dns_pkt *rdns = unparse_dns_packet (pdns); size_t size = sizeof (struct GNUNET_MESH_Tunnel *) + -- 2.25.1