]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG: dns: Prevent out-of-bounds read in dns_validate_dns_response()
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 5 Dec 2018 16:56:29 +0000 (17:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Dec 2018 13:44:29 +0000 (14:44 +0100)
We need to make sure that the record length is not making us read
past the end of the data we received.
Before this patch we could for example read the 16 bytes
corresponding to an AAAA record from the non-initialized part of
the buffer, possibly accessing anything that was left on the stack,
or even past the end of the 8193-byte buffer, depending on the
value of accepted_payload_size.

To be backported to 1.8, probably also 1.7.

src/dns.c

index fead2613ad7bc4258bc8925e2c3aa9a46f462a67..c1396f525985de4d0494dc1d28cb960d19118d84 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -810,6 +810,11 @@ static int dns_validate_dns_response(unsigned char *resp, unsigned char *bufend,
                /* Move forward 2 bytes for data len */
                reader += 2;
 
+               if (reader + dns_answer_record->data_len >= bufend) {
+                       pool_free(dns_answer_item_pool, dns_answer_record);
+                       return DNS_RESP_INVALID;
+               }
+
                /* Analyzing record content */
                switch (dns_answer_record->type) {
                        case DNS_RTYPE_A: