From f021da2afa0d07dd142ee4fa8940757ceebb0d24 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Thu, 6 Oct 2022 23:39:31 +0200 Subject: [PATCH] UI: Copy result of getenv before use Another call to getenv, as well as a call to the POSIX functions setenv(), unsetenv(), and putenv() may invalidate the pointer returned by a previous call or modify the string obtained from a previous call. https://en.cppreference.com/w/c/program/getenv --- UI/window-basic-main.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 068888204..c53f85b9f 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -154,13 +154,22 @@ template static void SetOBSRef(QListWidgetItem *item, T &&val) static void AddExtraModulePaths() { - char *plugins_path = getenv("OBS_PLUGINS_PATH"); - char *plugins_data_path = getenv("OBS_PLUGINS_DATA_PATH"); - if (plugins_path && plugins_data_path) { + string plugins_path, plugins_data_path; + char *s; + + s = getenv("OBS_PLUGINS_PATH"); + if (s) + plugins_path = s; + + s = getenv("OBS_PLUGINS_DATA_PATH"); + if (s) + plugins_data_path = s; + + if (!plugins_path.empty() && !plugins_data_path.empty()) { string data_path_with_module_suffix; data_path_with_module_suffix += plugins_data_path; data_path_with_module_suffix += "/%module%"; - obs_add_module_path(plugins_path, + obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str()); }