dnsproxy: Fix cached message length correctly
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Sun, 7 Apr 2013 14:52:37 +0000 (17:52 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 8 Apr 2013 06:16:39 +0000 (09:16 +0300)
We must copy the response buffer before fixing the packet length.
Otherwise the packet length will go wrong if the request contained
EDNS0 data.

src/dnsproxy.c

index 388ea4b..52d67d4 100644 (file)
@@ -1556,12 +1556,16 @@ static int cache_update(struct server_data *srv, unsigned char *msg,
         * two bytes. This way we do not need to know the format
         * (UDP/TCP) of the cached message.
         */
+       if (srv->protocol == IPPROTO_UDP)
+               memcpy(ptr + 2, msg, offset + 12);
+       else
+               memcpy(ptr, msg, offset + 12);
+
        ptr[0] = (data->data_len - 2) / 256;
        ptr[1] = (data->data_len - 2) - ptr[0] * 256;
        if (srv->protocol == IPPROTO_UDP)
                ptr += 2;
 
-       memcpy(ptr, msg, offset + 12);
        memcpy(ptr + offset + 12, question, qlen + 1); /* copy also the \0 */
 
        q = (void *) (ptr + offset + 12 + qlen + 1);