Current evdns code does not check QUESTIONS section in DNS reply, but it
is wrong by design: we cannot fully avoid id collision on highly loaded
systems. My suggestion is to check request QUESTIONS section and reply
QUESTIONS section and do not try to send to user's callback wrong data.
Patch can be look like this.
diff -r adf7b7ca412b -r f6cd10895ea3 evdns.c
--- a/evdns.c Thu Aug 21 18:37:34 2008 +0400
+++ b/evdns.c Wed Aug 27 17:33:07 2008 +0400
@@ -849,10 +849,10 @@ name_parse(u8 *packet, int length, int *
/* parses a raw request from a nameserver */
static int
reply_parse(u8 *packet, int length) {
- int j = 0; /* index into packet */
+ int j = 0, k = 0; /* index into packet */
u16 _t; /* used by the macros */
u32 _t32; /* used by the macros */
- char tmp_name[256]; /* used by the macros */
+ char tmp_name[256], tmp1_name[256]; /* used by the macros */
u16 trans_id, questions, answers, authority, additional, datalength;
u16 flags = 0;
@@ -885,10 +885,22 @@ reply_parse(u8 *packet, int length) {
/* This macro skips a name in the DNS reply. */
#define SKIP_NAME \
- do { tmp_name[0] = '\0'; \
- if (name_parse(packet, length, &j, tmp_name, sizeof(tmp_name))<0) \
- goto err; \
- } while(0);
+ do { tmp_name[0] = '\0'; \
+ if (name_parse(packet, length, &j, tmp_name, sizeof(tmp_name))<0) \
+ goto err; \
+ } while(0)
+#define TEST_NAME \
+ do { tmp_name[0] = '\0'; \
+ tmp1_name[0] = '\0'; \
+ k = j; \
+ if (name_parse(packet, length, &j, tmp_name, sizeof(tmp_name))<0) \
+ goto err; \
+ if (name_parse(req->request, req->request_len, &k, tmp1_name, sizeof(tmp1_name))<0) \
+ goto err; \
+ if (memcmp (tmp_name, tmp1_name, strlen (tmp_name)) != 0) { \
+ goto err; \
+ } \
+ } while(0)
reply.type = req->request_type;
@@ -897,7 +909,7 @@ reply_parse(u8 *packet, int length) {
/* the question looks like
* <label:name><u16:type><u16:class>
*/
- SKIP_NAME;
+ TEST_NAME;
j += 4;
if (j > length) goto err;
}
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users