shithub: plan9front

Download patch

ref: b2ef0ff49de457a6e48751e7eedd8131cdca5f98
parent: 192c1fd73a54870f8736908886d7fe0905e5ec58
author: Humm <hummsmith42@gmail.com>
date: Wed Apr 21 02:28:32 EDT 2021

plumber: fix substrings in match rules

Unmatched substrings are nil, so we can't rely on nil terminating the
array of substrings.

--- a/sys/src/cmd/plumb/match.c	Tue Apr 20 12:12:54 2021
+++ b/sys/src/cmd/plumb/match.c	Wed Apr 21 02:28:32 2021
@@ -36,12 +36,13 @@
 		free(match[i]);
 		match[i] = nil;
 	}
-	for(i=0; i<10 && rs[i].sp!=nil; i++){
-		n = rs[i].ep-rs[i].sp;
-		match[i] = emalloc(n+1);
-		memmove(match[i], rs[i].sp, n);
-		match[i][n] = '\0';
-	}
+	for(i=0; i<10; i++)
+		if(rs[i].sp!=nil){
+			n = rs[i].ep-rs[i].sp;
+			match[i] = emalloc(n+1);
+			memmove(match[i], rs[i].sp, n);
+			match[i][n] = '\0';
+		}
 }
 
 int