[runtime] Switch getenv to use heap memory
authorAlexander Kyte <alexmkyte@gmail.com>
Mon, 27 Mar 2017 06:18:43 +0000 (02:18 -0400)
committerAlexander Kyte <alexmkyte@gmail.com>
Thu, 30 Mar 2017 17:58:10 +0000 (13:58 -0400)
commit399f6e2425d5fdf73c4f956e9e906613b55968d0
tree539a8e1dcbd585c4c31b0e35897cd62dafbf045f
parent2bf7d1b5252a785ef13063bb9487eec1848fcd31
[runtime] Switch getenv to use heap memory

Getenv doesn't use heap memory, it uses static memory.
Mono's usage is consistent with a view of getenv memory contents
that are durable and can be stored and manipulated.

In a multithreaded context, getenv calls can race and corrupt
string buffers as they are read. In a single threaded context,
subsequent calls to getenv will lead to overwriting the memory
that pointers to previous calls point to.

In order to bring memory safety back, we duplicate memory and
manage it at each call-site.

Note: this changes the API semantics of g_getenv. This is necessary
because the locking around the getenv buffer is safest when confined to
the function in eglib.
44 files changed:
eglib/src/glib.h
eglib/src/gmisc-unix.c
eglib/src/gmisc-win32.c
mono/arch/ia64/codegen.c
mono/metadata/appdomain.c
mono/metadata/assembly.c
mono/metadata/boehm-gc.c
mono/metadata/class.c
mono/metadata/cominterop.c
mono/metadata/console-unix.c
mono/metadata/icall.c
mono/metadata/image.c
mono/metadata/locales.c
mono/metadata/lock-tracer.c
mono/metadata/mono-config.c
mono/metadata/threadpool-io.c
mono/metadata/w32file-unix.c
mono/mini/aot-runtime.c
mono/mini/debugger-agent.c
mono/mini/driver.c
mono/mini/helpers.c
mono/mini/ir-emit.h
mono/mini/liveness.c
mono/mini/llvm-jit.cpp
mono/mini/method-to-ir.c
mono/mini/mini-arm.c
mono/mini/mini-cross-helpers.c
mono/mini/mini-gc.c
mono/mini/mini-llvm.c
mono/mini/mini-ppc.h
mono/mini/mini-runtime.c
mono/mini/mini-x86.c
mono/mini/mini.c
mono/profiler/mono-profiler-log.c
mono/sgen/sgen-gc.c
mono/utils/checked-build.c
mono/utils/mono-hwcap.c
mono/utils/mono-io-portability.c
mono/utils/mono-logger.c
mono/utils/mono-mmap.c
mono/utils/mono-rand.c
mono/utils/mono-threads-coop.c
mono/utils/mono-threads.c
mono/utils/strenc.c