From d9273ed5ed0a01c6db78f11d3cba753a5bf6b4b6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 15 Jul 2017 14:55:06 +0800 Subject: [PATCH] deps: cherry-pick 18ea996 from c-ares upstream Original commit message: ares_parse_naptr_reply: make buffer length check more accurate 9478908a490a6bf009ba58d81de8c1d06d50a117 introduced a length check for records parsed by `ares_parse_naptr_reply()`. However, that function is designed to parse replies which also contain non-NAPTR records; for A records, the `rr_len > 7` check will fail as there are only 4 bytes of payload. In particular, parsing ANY replies for NAPTR records was broken by that patch. Fix that by moving the check into the case in which it is already known that the record is a NAPTR record. Ref: https://github.com/c-ares/c-ares/commit/18ea99693d63f957ecb670045adbd2c1da8a4641 PR-URL: https://github.com/nodejs/node/pull/13883 Reviewed-By: James M Snell --- deps/cares/src/ares_parse_naptr_reply.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/deps/cares/src/ares_parse_naptr_reply.c b/deps/cares/src/ares_parse_naptr_reply.c index 717d355778117f..a14c226a9e7e25 100644 --- a/deps/cares/src/ares_parse_naptr_reply.c +++ b/deps/cares/src/ares_parse_naptr_reply.c @@ -110,18 +110,19 @@ ares_parse_naptr_reply (const unsigned char *abuf, int alen, status = ARES_EBADRESP; break; } - /* RR must contain at least 7 bytes = 2 x int16 + 3 x name */ - if (rr_len < 7) - { - status = ARES_EBADRESP; - break; - } /* Check if we are really looking at a NAPTR record */ if (rr_class == C_IN && rr_type == T_NAPTR) { /* parse the NAPTR record itself */ + /* RR must contain at least 7 bytes = 2 x int16 + 3 x name */ + if (rr_len < 7) + { + status = ARES_EBADRESP; + break; + } + /* Allocate storage for this NAPTR answer appending it to the list */ naptr_curr = ares_malloc_data(ARES_DATATYPE_NAPTR_REPLY); if (!naptr_curr)