summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@markovcorp.com>2018-01-25 18:33:17 -0800
committerOri Bernstein <ori@markovcorp.com>2018-01-25 18:33:17 -0800
commit58633cbf5d7bbbf095787b7b01b6ad6b032def3c (patch)
treea2ff21ab85332a9d0b95bfbc0a56dcc9950f5e5d
parent0b3e6b3218f6cbcd0157265bfcf01df880a88ee7 (diff)
downloadmc-58633cbf5d7bbbf095787b7b01b6ad6b032def3c.tar.gz
Ensure null termination of environment list.
-rw-r--r--lib/std/env+posixy.myr8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/std/env+posixy.myr b/lib/std/env+posixy.myr
index fe73c7e..2722aa0 100644
--- a/lib/std/env+posixy.myr
+++ b/lib/std/env+posixy.myr
@@ -10,6 +10,7 @@ use "option"
use "sldup"
use "slcp"
use "sleq"
+use "slpush"
pkg std =
const getenv : (name : byte[:] -> option(byte[:]))
@@ -49,6 +50,9 @@ const setenv = {name, val
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 @@ const setenv = {name, val
;;
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)