From d692ea1f0ca17e1eb8f0cb218887c1af6b8fb581 Mon Sep 17 00:00:00 2001
From: Leif Stensson <leif@lysator.liu.se>
Date: Thu, 7 Sep 2000 17:29:41 +0200
Subject: [PATCH] Two avoid-backtraces fixes. One to catch errors from
 udp->wait(), and one to handle some cases of get_tcpip_param() returning 0.

Rev: lib/modules/Protocols.pmod/DNS.pmod:1.48
---
 lib/modules/Protocols.pmod/DNS.pmod | 45 ++++++++++++++++-------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/lib/modules/Protocols.pmod/DNS.pmod b/lib/modules/Protocols.pmod/DNS.pmod
index 56250c61db..49d439fa4c 100644
--- a/lib/modules/Protocols.pmod/DNS.pmod
+++ b/lib/modules/Protocols.pmod/DNS.pmod
@@ -405,7 +405,7 @@ class client
   static private mapping etc_hosts;
 
 #ifdef __NT__
-  string get_tcpip_param(string val)
+  string get_tcpip_param(string val, void|string fallbackvalue)
   {
     foreach(({
       "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
@@ -430,7 +430,7 @@ class client
 	};
       }
 #endif
-			   
+    return fallbackvalue;
   }
 #endif
   
@@ -484,15 +484,15 @@ class client
       string domain;
 
 #if __NT__
-      domain=get_tcpip_param("Domain");
+      domain = get_tcpip_param("Domain");
       if(!domain || !sizeof(domain))
-        domain=get_tcpip_param("DhcpDomain");
+        domain = get_tcpip_param("DhcpDomain");
 
-      nameservers = get_tcpip_param("NameServer") / " ";
-      nameservers+= get_tcpip_param("DhcpNameServer") / " ";
-      nameservers -= ({""});
+      nameservers += get_tcpip_param("NameServer", "") / " ";
+      nameservers += get_tcpip_param("DhcpNameServer", "") / " ";
+      nameservers -= ({ "" });
 
-      domains=get_tcpip_param("SearchList") / " "- ({""});
+      domains += (get_tcpip_param("SearchList", "") / " ") - ({ "" });
 #else
       string resolv_conf;
       foreach(({"/etc/resolv.conf", "/amitcp/db/resolv.conf"}), string resolv_loc)
@@ -583,18 +583,23 @@ class client
     for (i=0; i < RETRIES; i++) {
       udp->send(nameservers[i % sizeof(nameservers)], 53, s);
 
-      while (udp->wait(RETRY_DELAY)) {
-	// udp->read() can throw an error on connection refused.
-	catch {
-	  m = udp->read();
-	  if ((m->port == 53) &&
-	      (m->data[0..1] == s[0..1]) &&
-	      (search(nameservers, m->ip) != -1)) {
-	    // Success.
-	    return decode_res(m->data);
-	  }
-	};
-      }
+      // upd->wait() can throw an error sometimes.
+      catch
+      {
+  	while (udp->wait(RETRY_DELAY))
+        {
+  	  // udp->read() can throw an error on connection refused.
+  	  catch {
+  	    m = udp->read();
+  	    if ((m->port == 53) &&
+  		(m->data[0..1] == s[0..1]) &&
+  		(search(nameservers, m->ip) != -1)) {
+  	      // Success.
+  	      return decode_res(m->data);
+  	    }
+  	  };
+        }
+      };
     }
     // Failure.
     return 0;
-- 
GitLab