diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2024-09-15 21:16:34 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2024-09-20 08:56:16 +0200 |
commit | 7af80d986f836396977e25ccf2487414fc080400 (patch) | |
tree | e0b44b667f2c0007d4689abaeadff2e200f3d4cd | |
parent | 6ea37c8fa4c4780ff99441ac787a2c9cd38c7bc6 (diff) |
lib: use copy of environ pointer in getenv()
Without this fix a call to getenv() without parameters destroys environ,
and subsequent calls to getenv() (with or without parameter) return
nothing.
Fixes: #219
Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
-rw-r--r-- | lib.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -854,21 +854,22 @@ uc_getenv(uc_vm_t *vm, size_t nargs) { uc_value_t *key = uc_fn_arg(0), *rv = NULL; extern char **environ; + char **env = environ; char *k, *v; if (!key) { rv = ucv_object_new(vm); - while (*environ) { - v = strchr(*environ, '='); + while (*env) { + v = strchr(*env, '='); if (v) { - xasprintf(&k, "%.*s", (int)(v - *environ), *environ); + xasprintf(&k, "%.*s", (int)(v - *env), *env); ucv_object_add(rv, k, ucv_string_new(v + 1)); free(k); } - environ++; + env++; } } else if (ucv_type(key) == UC_STRING) { |