GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dns: setServers throws inconsistent TypeError · Issue #20441 · nodejs/node

dns: setServers throws inconsistent TypeError #20441

New issue
Copy link
New issue
Copy link
Closed
Closed
dns: setServers throws inconsistent TypeError#20441
Copy link

Description

@davisjam
davisjam
opened on May 1, 2018
Issue body actions
  • Version
./out/Release/node  --version
v11.0.0-pre
  • Platform
(20:24:36) jamie@woody ~/Desktop/floss/node $ uname -a
Linux woody 4.13.0-38-generic #43~16.04.1-Ubuntu SMP Wed Mar 14 17:48:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem

DNS

Problematic behavior

The dns.setServers API responds inconsistently on different invalid input.

Good behavior:

dns.setServers([' '])
TypeError [ERR_INVALID_IP_ADDRESS]: Invalid IP address:  
    at servers.forEach (dns.js:319:11)
    at Array.forEach (<anonymous>)
    at Resolver.setServers (dns.js:295:11)
    at Object.defaultResolverSetServers [as setServers] (dns.js:360:12)

Bad behavior:

> dns.setServers(['\n'])
TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null
    at servers.forEach (dns.js:312:27)
    at Array.forEach (<anonymous>)
    at Resolver.setServers (dns.js:295:11)
    at Object.defaultResolverSetServers [as setServers] (dns.js:360:12)

A null pointer dereference is rather less nice than an error like ERR_INVALID_IP_ADDRESS.

I believe the problem is in dns.js:

...
  servers.forEach((serv) => {
    ...
    const match = serv.match(IPv6RE);
    // we have an IPv6 in brackets
    if (match) {
       ....
    }
    ...
    const [, s, p] = serv.match(addrSplitRE);

While the IPv6 code only accesses match if there was a match, the addrSplitRE code assumes there is a match, which can lead to this unsavory TypeError.

Activity

  1. davisjam commented on May 1, 2018

    @davisjam
    davisjam
    on May 1, 2018
    ContributorAuthor
    More actions

    Working on a PR

  2. davisjam
    added a commit that references this issue on May 1, 2018

    dns: make invalid setServers yield uniform error

    cd73836
  3. Trott
    added a commit that references this issue on Jun 9, 2018

    dns: improve setServers() errors and performance

    872c331
  4. Trott
    closed this as completedin 872c331on Jun 9, 2018
  5. targos
    added a commit that references this issue on Jun 10, 2018

    dns: improve setServers() errors and performance

    ab554d1
  6. targos
    added a commit that references this issue on Jun 13, 2018

    dns: improve setServers() errors and performance

    65b9c42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.