Browse Source

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
Richard Stanway 3 years ago
parent
commit
f021da2afa
1 changed files with 13 additions and 4 deletions
  1. 13 4
      UI/window-basic-main.cpp

+ 13 - 4
UI/window-basic-main.cpp

@@ -154,13 +154,22 @@ template<typename T> 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());
 	}