shithub: mc

Download patch

ref: 58633cbf5d7bbbf095787b7b01b6ad6b032def3c
parent: 0b3e6b3218f6cbcd0157265bfcf01df880a88ee7
author: Ori Bernstein <[email protected]>
date: Thu Jan 25 13:33:17 EST 2018

Ensure null termination of environment list.

--- a/lib/std/env+posixy.myr
+++ b/lib/std/env+posixy.myr
@@ -10,6 +10,7 @@
 use "sldup"
 use "slcp"
 use "sleq"
+use "slpush"
 
 pkg std =
 	const getenv	: (name : byte[:] -> option(byte[:]))
@@ -49,6 +50,9 @@
 	envdup()
 	idx = 0
 	for envp : environ
+		if envp == Zenvp
+			break
+		;;
 		env = cstrconvp(envp)
 		n = min(name.len, env.len)
 		if sleq(name, env[:n]) && sleq(env[n:n+1], "=")
@@ -56,8 +60,8 @@
 		;;
 		idx++
 	;;
-	if idx == environ.len
-		slgrow(&environ, environ.len + 1)
+	if idx == environ.len - 1
+		slpush(&environ, (0 : byte#))
 	else
 		e = cstrconvp(environ[idx])
 		std.slfree(e)