From ba431b5efc178fe2f479b6cfc8612d2af11e005c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Nov 2019 19:24:26 +0100 Subject: net.resolvers: Apply IDNA conversion to ascii for DNS lookups (fixes #1426) --- net/resolvers/basic.lua | 3 ++- net/resolvers/service.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'net/resolvers') diff --git a/net/resolvers/basic.lua b/net/resolvers/basic.lua index 9a3c9952..d8031a6b 100644 --- a/net/resolvers/basic.lua +++ b/net/resolvers/basic.lua @@ -1,5 +1,6 @@ local adns = require "net.adns"; local inet_pton = require "util.net".pton; +local idna_to_ascii = require "util.encodings".idna.to_ascii; local methods = {}; local resolver_mt = { __index = methods }; @@ -59,7 +60,7 @@ end local function new(hostname, port, conn_type, extra) return setmetatable({ - hostname = hostname; + hostname = idna_to_ascii(hostname); port = port; conn_type = conn_type or "tcp"; extra = extra; diff --git a/net/resolvers/service.lua b/net/resolvers/service.lua index b5a2d821..a76adb73 100644 --- a/net/resolvers/service.lua +++ b/net/resolvers/service.lua @@ -1,5 +1,6 @@ local adns = require "net.adns"; local basic = require "net.resolvers.basic"; +local idna_to_ascii = require "util.encodings".idna.to_ascii; local methods = {}; local resolver_mt = { __index = methods }; @@ -58,7 +59,7 @@ end local function new(hostname, service, conn_type, extra) return setmetatable({ - hostname = hostname; + hostname = idna_to_ascii(hostname); service = service; conn_type = conn_type or "tcp"; extra = extra; -- cgit v1.2.3 From 9c2a74d09c9c45d165a4bcf51f4debfac8877e36 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 2 Nov 2019 19:36:19 +0100 Subject: net.resolvers: Abort on hostnames not passing IDNA validation Prevents error on trying to use nil. Needs better error reporting in the future. --- net/resolvers/basic.lua | 5 +++++ net/resolvers/service.lua | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'net/resolvers') diff --git a/net/resolvers/basic.lua b/net/resolvers/basic.lua index d8031a6b..cafef58b 100644 --- a/net/resolvers/basic.lua +++ b/net/resolvers/basic.lua @@ -18,6 +18,11 @@ function methods:next(cb) return; end + if not self.hostname then + -- FIXME report IDNA error + cb(nil); + end + local targets = {}; local n = 2; local function ready() diff --git a/net/resolvers/service.lua b/net/resolvers/service.lua index a76adb73..bb255c33 100644 --- a/net/resolvers/service.lua +++ b/net/resolvers/service.lua @@ -25,6 +25,11 @@ function methods:next(cb) return; end + if not self.hostname then + -- FIXME report IDNA error + cb(nil); + end + local targets = {}; local function ready() self.targets = targets; -- cgit v1.2.3