shithub: riscv

Download patch

ref: 8e53fe132efe25437f50974f107be4f1fcbad2ea
parent: bc4469e5d23509cd7f9070278b146c467d5f120a
author: cinap_lenrek <[email protected]>
date: Tue May 1 18:17:27 EDT 2018

ndb/cs: fix crash in ndbredorder due to ndbnew() not maintaining the ->line ring

we have to maintain the ->line chain for ndbreorder() to work, so add
a little helper: ndbline() which replicates the ->entry chain and links
the last tuple to the first; makeing the whole list into a single line.

--- a/sys/src/cmd/ndb/cs.c
+++ b/sys/src/cmd/ndb/cs.c
@@ -1386,6 +1386,20 @@
 	return parseip(ip, s) != -1 && isv4(ip);
 }
 
+static Ndbtuple*
+ndbline(Ndbtuple *t)
+{
+	Ndbtuple *nt;
+
+	for(nt = t; nt != nil; nt = nt->entry){
+		if(nt->entry == nil)
+			nt->line = t;
+		else
+			nt->line = nt->entry;
+	}
+	return t;
+}
+
 /*
  *  lookup an ip destination
  */
@@ -1410,13 +1424,13 @@
 
 	/* for dial strings with no host */
 	if(strcmp(host, "*") == 0)
-		return ndbnew("ip", "*");
+		return ndbline(ndbnew("ip", "*"));
 
 	/*
 	 *  hack till we go v6 :: = 0.0.0.0
 	 */
 	if(strcmp("::", host) == 0)
-		return ndbnew("ip", "*");
+		return ndbline(ndbnew("ip", "*"));
 
 	/*
 	 *  just accept addresses
@@ -1423,7 +1437,7 @@
 	 */
 	attr = ipattr(host);
 	if(strcmp(attr, "ip") == 0)
-		return ndbnew("ip", host);
+		return ndbline(ndbnew("ip", host));
 
 	/*
 	 *  give the domain name server the first opportunity to
@@ -1627,14 +1641,8 @@
 		if (strcmp(tt->attr, "ipv6") == 0)
 			strcpy(tt->attr, "ip");
 
-	if (t == nil)
-		return t6;
-
 	/* append t6 list to t list */
-	for (tt = t; tt->entry != nil; tt = tt->entry)
-		;
-	tt->entry = t6;
-	return t;
+	return ndbconcatenate(t, t6);
 }
 
 /*
@@ -1911,12 +1919,7 @@
 	}
 
 	/* make it all one line */
-	for(nt = t; nt != nil; nt = nt->entry){
-		if(nt->entry == nil)
-			nt->line = t;
-		else
-			nt->line = nt->entry;
-	}
+	t = ndbline(t);
 
 	qreply(mf, t);