From 2fcbb886d736ad7dbc5f662bf4e1d0d0e4974d80 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Thu, 31 Jan 2019 13:02:59 +0800 Subject: [PATCH] deps: patch to fix *.onion MX query on c-ares c-ares rejects *.onion MX query but forgot to set `*bufp` to NULL. This will occur SegmentFault when free `*bufp`. I make this quick fix and then will make a PR for c-ares either. PR-URL: https://github.com/nodejs/node/pull/25840 Fixes: https://github.com/nodejs/node/issues/25839 Refs: https://github.com/c-ares/c-ares/blob/955df98/ares_create_query.c#L97-L103 Refs: https://github.com/c-ares/c-ares/blob/955df98/ares_query.c#L124 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: James M Snell --- deps/cares/src/ares_create_query.c | 8 ++++---- test/parallel/test-dns.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/deps/cares/src/ares_create_query.c b/deps/cares/src/ares_create_query.c index 1606b1a1004706..9efce17cfa32aa 100644 --- a/deps/cares/src/ares_create_query.c +++ b/deps/cares/src/ares_create_query.c @@ -94,14 +94,14 @@ int ares_create_query(const char *name, int dnsclass, int type, size_t buflen; unsigned char *buf; - /* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */ - if (ares__is_onion_domain(name)) - return ARES_ENOTFOUND; - /* Set our results early, in case we bail out early with an error. */ *buflenp = 0; *bufp = NULL; + /* Per RFC 7686, reject queries for ".onion" domain names with NXDOMAIN. */ + if (ares__is_onion_domain(name)) + return ARES_ENOTFOUND; + /* Allocate a memory area for the maximum size this packet might need. +2 * is for the length byte and zero termination if no dots or ecscaping is * used. diff --git a/test/parallel/test-dns.js b/test/parallel/test-dns.js index eb02d4e92d647d..fb2939dd61422e 100644 --- a/test/parallel/test-dns.js +++ b/test/parallel/test-dns.js @@ -314,3 +314,13 @@ common.expectsError(() => { code: 'ERR_INVALID_CALLBACK', type: TypeError }); + +{ + dns.resolveMx('foo.onion', function(err) { + assert.deepStrictEqual(err.errno, 'ENOTFOUND'); + assert.deepStrictEqual(err.code, 'ENOTFOUND'); + assert.deepStrictEqual(err.syscall, 'queryMx'); + assert.deepStrictEqual(err.hostname, 'foo.onion'); + assert.deepStrictEqual(err.message, 'queryMx ENOTFOUND foo.onion'); + }); +}