From 462b4baf33fce4b7876c4269f545941d7ec7858a Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Thu, 23 Feb 2017 16:36:20 +0100 Subject: [PATCH] ruby_setenv: Do not allow on multi-threaded programs --- hash.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hash.c b/hash.c index 1867c0999c198c..a4f519202f537a 100644 --- a/hash.c +++ b/hash.c @@ -3382,9 +3382,18 @@ check_envname(const char *name) } #endif +static void +check_running_threads(void) +{ + if (!rb_thread_alone()) + rb_raise(rb_eRuntimeError, "cannot setenv() in a multi-threaded program"); +} + void ruby_setenv(const char *name, const char *value) { + check_running_threads(); + #if defined(_WIN32) # if defined(MINGW_HAS_SECURE_API) || RUBY_MSVCRT_VERSION >= 80 # define HAVE__WPUTENV_S 1