From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.bugs Subject: bug#40343: 28.0.50; dns-set-servers fails on IPv6 available Windows Date: Fri, 03 Apr 2020 10:42:24 +0200 Message-ID: References: <86v9mkmwnq.wl--xmue@d1.dion.ne.jp> <86zhbvxqx3.wl--xmue@d1.dion.ne.jp> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="18603"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 40343@debbugs.gnu.org To: Kazuhiro Ito Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 03 10:43:53 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jKHvc-00043N-8r for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Apr 2020 10:43:52 +0200 Original-Received: from localhost ([::1]:52182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHux-0003Df-Lm for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Apr 2020 04:43:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47786) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHuq-0003CK-AD for bug-gnu-emacs@gnu.org; Fri, 03 Apr 2020 04:43:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKHup-0006pQ-1e for bug-gnu-emacs@gnu.org; Fri, 03 Apr 2020 04:43:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jKHuo-0006p0-Py for bug-gnu-emacs@gnu.org; Fri, 03 Apr 2020 04:43:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jKHuo-0003dt-Ad for bug-gnu-emacs@gnu.org; Fri, 03 Apr 2020 04:43:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Apr 2020 08:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40343 X-GNU-PR-Package: emacs Original-Received: via spool by 40343-submit@debbugs.gnu.org id=B40343.158590335413906 (code B ref 40343); Fri, 03 Apr 2020 08:43:02 +0000 Original-Received: (at 40343) by debbugs.gnu.org; 3 Apr 2020 08:42:34 +0000 Original-Received: from localhost ([127.0.0.1]:41150 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jKHuM-0003cB-BM for submit@debbugs.gnu.org; Fri, 03 Apr 2020 04:42:34 -0400 Original-Received: from mail-wr1-f45.google.com ([209.85.221.45]:35187) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jKHuK-0003bf-96 for 40343@debbugs.gnu.org; Fri, 03 Apr 2020 04:42:33 -0400 Original-Received: by mail-wr1-f45.google.com with SMTP id g3so5197758wrx.2 for <40343@debbugs.gnu.org>; Fri, 03 Apr 2020 01:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:message-id:mime-version; bh=MBU0pcKxcXgydUtyBSFRjJpRd11dBsH6HB4fnPYdShg=; b=FhzugNcQ8nUq+n0y6DxR7l7Eftyj2jtsO3g+wTuM2sBsdTY2vfjyiWlHq/v56es6HL CztaY34i3itlrWmnGe03mnObNRtw5k9h19Z3woG2qm7QHOYL/Wbl3nl/tKNdwessuYu0 6aNheH8Bu4QceA2uEM4jhO8J3UBjT3PBv/o7xac2oHXRNlxuRQw34V3vgKkYnQLZfOnd fyUikTtpqhwqT96QSxwrjXcds8IgHOZggRVb4kH51/3a3m2zunCDrwWWNOp5lyOZXttP 6P95JHBP0LFWBx1F6XPes9aDUn91L0h+fFPtUvJkY/nefPNmAbvqTmpMbFLi0DokAtUm zeXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:message-id :mime-version; bh=MBU0pcKxcXgydUtyBSFRjJpRd11dBsH6HB4fnPYdShg=; b=LMV47lM2Vhli40JBbUcvg96akJGjjFpAlezWkGiQo0P9vor2Vr0cqCTy3SeFef36ov ItCTr1Y8b1zcCts2TrfwYsxEMhjmmz7BWv+lm4XxJPx4Q5Usp4o01AE5JtDd/anGGVbV ykOH4Zg1hL058lcMxRwrAi2RJ8qBhS3xR/h3P+N7wKcyU6RgbylKyoc9hH6pXeNS5yrQ 36ndihMKrZfV50BYQOrdl/Guaw38jRhjfPPfgcYnvd79C8I88AhyGlVteQJTFK+GN4ku 6n2mEVV5zaWYILvBB/gaqVMBSoNUkZhYOCDZTEEfdH526FLd9lOFi2wUQRs7mWXpRMu/ /b2g== X-Gm-Message-State: AGi0PuYVNIIvZP1v4bxXLLeNoM5o712TrfgsfX7Ti56sXsJqOse+0+PX /Q21dLmSK7IlLYlt1GxnHu0HweB6 X-Google-Smtp-Source: APiQypKoyWTprx+9TtiK4H8dQQ7YInPsgYvMUssMo3KEfjAt0y4QWiFKwVlY/kHMU0egWWhvmps5QA== X-Received: by 2002:adf:fd47:: with SMTP id h7mr7715150wrs.105.1585903345917; Fri, 03 Apr 2020 01:42:25 -0700 (PDT) Original-Received: from rpluim-mac ([2a01:e34:ecfc:a860:30c1:b817:7653:c738]) by smtp.gmail.com with ESMTPSA id i97sm6304535wri.1.2020.04.03.01.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2020 01:42:25 -0700 (PDT) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177976 Archived-At: >>>>> On Wed, 01 Apr 2020 23:55:12 +0900, Kazuhiro Ito said: Kazuhiro> I tested on Debian box as below. Kazuhiro> 1. /etc/init.d/networking stop Kazuhiro> 2. remove nameserver entry from /etc/resolv.conf Kazuhiro> On such condition, nslookup program outputs as below >> ;; connection timed out; no servers could be reached Kazuhiro> Here is code snippet communicating with nslookup in dns-set-servers. >> (with-temp-buffer >> (call-process "nslookup" nil t nil "localhost") >> (goto-char (point-min)) >> (re-search-forward >> "^Address:[ \t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\)" nil t) >> (setq dns-servers (list (match-string 1)))) Kazuhiro> On the above condition, re-search-forward doesn't match anything. But Kazuhiro> next match-string is called unconditionally. As far as I tested, Kazuhiro> match-string's result when last search didn't match is undefined. it Kazuhiro> may return nil, string or raise an error. Additionally, even if Kazuhiro> match-string returns nil, dns-servers is never set to nil. It is set Kazuhiro> to (nil). Thanks for that. This should fix all those cases: diff --git a/lisp/net/dns.el b/lisp/net/dns.el index 78d4827162..177df4e332 100644 --- a/lisp/net/dns.el +++ b/lisp/net/dns.el @@ -315,8 +315,8 @@ dns-servers-up-to-date-p (defun dns-set-servers () "Set `dns-servers' to a list of DNS servers or nil if none are found. Parses \"/etc/resolv.conf\" or calls \"nslookup\"." + (setq dns-servers nil) (or (when (file-exists-p "/etc/resolv.conf") - (setq dns-servers nil) (with-temp-buffer (insert-file-contents "/etc/resolv.conf") (goto-char (point-min)) @@ -327,9 +327,9 @@ dns-set-servers (with-temp-buffer (call-process "nslookup" nil t nil "localhost") (goto-char (point-min)) - (re-search-forward - "^Address:[ \t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\)" nil t) - (setq dns-servers (list (match-string 1)))))) + (when (re-search-forward + "^Address:[ \t]*\\([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\\|[[:xdigit:]:]*\\)" nil t) + (setq dns-servers (list (match-string 1))))))) (when (fboundp 'network-interface-list) (setq dns-servers-valid-for-interfaces (network-interface-list)))) @@ -357,7 +357,9 @@ dns-make-network-process `(let ((server ,server) (coding-system-for-read 'binary) (coding-system-for-write 'binary)) - (if (fboundp 'make-network-process) + (if (and + (fboundp 'make-network-process) + (featurep 'make-network-process '(:type datagram))) (make-network-process :name "dns" :coding 'binary @@ -365,9 +367,9 @@ dns-make-network-process :host server :service "domain" :type 'datagram) - ;; Older versions of Emacs doesn't have - ;; `make-network-process', so we fall back on opening a TCP - ;; connection to the DNS server. + ;; Older versions of Emacs do not have `make-network-process', + ;; and on MS-Windows datagram sockets are not supported, so we + ;; fall back on opening a TCP connection to the DNS server. (open-network-stream "dns" (current-buffer) server "domain")))) (defvar dns-cache (make-vector 4096 0)) @@ -400,7 +402,9 @@ dns-query type 'PTR)) (if (not dns-servers) - (message "No DNS server configuration found") + (progn + (message "No DNS server configuration found") + nil) (with-temp-buffer (set-buffer-multibyte nil) (let ((process (condition-case ()