From 10ed7b38d43f9e9d94f91012888d24ef7792b156 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 9 Mar 2017 15:22:55 -0600 Subject: [PATCH] libc: initialize the environ pointer before Libc::construct Setting the global environ pointer to NULL prevents getenv surprises when using libc without the POSIX wrapper. Fix #2312 --- repos/libports/src/lib/libc/task.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/repos/libports/src/lib/libc/task.cc b/repos/libports/src/lib/libc/task.cc index 50ccdd02fe..acf551db53 100644 --- a/repos/libports/src/lib/libc/task.cc +++ b/repos/libports/src/lib/libc/task.cc @@ -37,6 +37,7 @@ #include "libc_init.h" #include "task.h" +extern char **environ; namespace Libc { class Env_implementation; @@ -844,6 +845,10 @@ Genode::size_t Component::stack_size() { return Libc::Component::stack_size(); } void Component::construct(Genode::Env &env) { + /* initialize the global pointer to environment variables */ + static char *null_env = nullptr; + if (!environ) environ = &null_env; + /* pass Genode::Env to libc subsystems that depend on it */ Libc::init_mem_alloc(env); Libc::init_dl(env);