code: plan9front

Download patch

ref: b2ef0ff49de457a6e48751e7eedd8131cdca5f98
parent: 192c1fd73a54870f8736908886d7fe0905e5ec58
author: Humm <hummsmith42@gmail.com>
date: Wed Apr 21 04: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
+++ b/sys/src/cmd/plumb/match.c
@@ -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