shithub: riscv

Download patch

ref: e168ea045f7c29afd41aeb5daf865a772fef2c9e
parent: c0280c607f92846cc05cb4a8c20c03fd4cea195a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Oct 13 05:02:04 EDT 2019

ndb/dns: handle empty $DNSSERVER

when $DNSSERVER is empty, query ndb for local dns servers
instead of not using any at all.

--- a/sys/src/cmd/ndb/dblookup.c
+++ b/sys/src/cmd/ndb/dblookup.c
@@ -937,11 +937,9 @@
 		return nsrp;
 
 	p = getenv("DNSSERVER");		/* list of ip addresses */
-	if(p != nil){
-		n = tokenize(p, args, nelem(args));
+	if(p != nil && (n = tokenize(p, args, nelem(args))) > 0){
 		for(i = 0; i < n; i++)
 			addlocaldnsserver(dp, class, args[i], i);
-		free(p);
 	} else {
 		t = lookupinfo("@dns");		/* @dns=ip1 @dns=ip2 ... */
 		if(t == nil)
@@ -953,6 +951,7 @@
 		}
 		ndbfree(t);
 	}
+	free(p);
 
 	return rrlookup(dp, Tns, NOneg);
 }