ref: 2307ddf98a7faefb1e0bacfb3248c35e7b1727c2
parent: 5c200bf5319760d03acccd835ea33dbb52b81249
	author: qwx <qwx@sciops.net>
	date: Mon Aug 18 12:00:52 EDT 2025
	
devenv: fix off-by-one in nul to space replacement (thanks cinap_lenrek) e->value may be nul-terminated, which is taken into account by e->len. commit c6f05d0f9d1cec898bce36caa693413759c6d4de unintentionally replaced that nul with a space before appending another nul. variables such as $mouseport would have a space character appended to their value and be no longer recognized in scripts like /rc/bin/screenrc. instead, check for any terminating nul characters and skip them.
--- a/sys/src/9/port/devenv.c
+++ b/sys/src/9/port/devenv.c
@@ -504,7 +504,7 @@
Egrp *eg = &confegrp;
Evalue *e;
char *p, *q;
- int i, n;
+ int i, n, m;
rlock(eg);
n = 1;
@@ -528,12 +528,16 @@
memmove(q, e->name, n);
q += n;
memmove(q, e->value, e->len);
- q[e->len] = 0;
-		for(n=0; n<e->len; n++){+		for(m = e->len; m > 0; m--){+ if(q[m-1] != '\0')
+ break;
+ }
+		for(n = 0; n < m; n++){if(q[n] == '\0')
q[n] = ' ';
}
- q += n+1;
+ q[m] = 0;
+ q += m+1;
}
*q = '\0';
runlock(eg);
--
⑨