TUI/thread: guard env map from potential race with unibilium #11259

unibi_from_term calls getenv internally, so exclusive control is required.
This commit is contained in:
erw7
2019-10-21 07:47:08 +09:00
committed by Justin M. Keyes
parent 019c8d13dd
commit 6fd6f4683d
2 changed files with 12 additions and 0 deletions

View File

@@ -44,6 +44,16 @@ void env_init(void)
uv_mutex_init(&mutex); uv_mutex_init(&mutex);
} }
void os_env_var_lock(void)
{
uv_mutex_lock(&mutex);
}
void os_env_var_unlock(void)
{
uv_mutex_unlock(&mutex);
}
/// Like getenv(), but returns NULL if the variable is empty. /// Like getenv(), but returns NULL if the variable is empty.
/// @see os_env_exists /// @see os_env_exists
const char *os_getenv(const char *name) const char *os_getenv(const char *name)

View File

@@ -234,7 +234,9 @@ static void terminfo_start(UI *ui)
// Set up unibilium/terminfo. // Set up unibilium/terminfo.
char *termname = NULL; char *termname = NULL;
if (term) { if (term) {
os_env_var_lock();
data->ut = unibi_from_term(term); data->ut = unibi_from_term(term);
os_env_var_unlock();
if (data->ut) { if (data->ut) {
termname = xstrdup(term); termname = xstrdup(term);
} }