Commit edd64c89 authored by Alexandre Savard's avatar Alexandre Savard

#14530: Validate environment variable from getenv in slfphoned

parent 0d09e0c7
......@@ -78,8 +78,8 @@ const char *get_data_dir()
bool create_pidfile()
{
const char * const xdg_env = XDG_CACHE_HOME;
std::string path = xdg_env ? xdg_env : std::string(HOMEDIR) + DIR_SEPARATOR_STR ".cache/";
std::string xdg_env(XDG_CACHE_HOME);
std::string path = (not xdg_env.empty()) ? xdg_env : std::string(HOMEDIR) + DIR_SEPARATOR_STR ".cache/";
if (!check_dir(path.c_str()))
return false;
......
......@@ -31,10 +31,14 @@
#ifndef FILEUTILS_H_
#define FILEUTILS_H_
#define HOMEDIR (getenv ("HOME")) /** Home directory */
#define XDG_DATA_HOME (getenv ("XDG_DATA_HOME"))
#define XDG_CONFIG_HOME (getenv ("XDG_CONFIG_HOME"))
#define XDG_CACHE_HOME (getenv ("XDG_CACHE_HOME"))
#define PROTECTED_GETENV(str) ({char *envvar_ = getenv((str)); \
envvar_ ? envvar_ : "";})
#define HOMEDIR (PROTECTED_GETENV("HOME"))
#define XDG_DATA_HOME (PROTECTED_GETENV("XDG_DATA_HOME"))
#define XDG_CONFIG_HOME (PROTECTED_GETENV("XDG_CONFIG_HOME"))
#define XDG_CACHE_HOME (PROTECTED_GETENV("XDG_CACHE_HOME"))
#define PIDFILE "sfl.pid"
......
......@@ -92,11 +92,8 @@ void History::ensurePath()
string userdata;
// If the environment variable is set (not null and not empty), we'll use it to save the history
// Else we 'll the standard one, ie: XDG_DATA_HOME = $HOMEDIR/.local/share/sflphone
if (XDG_DATA_HOME != NULL) {
string xdg_env(XDG_DATA_HOME);
(!xdg_env.empty()) ? userdata = xdg_env : userdata = xdg_data;
} else
userdata = xdg_data;
string xdg_env(XDG_DATA_HOME);
(not xdg_env.empty()) ? userdata = xdg_env : userdata = xdg_data;
if (mkdir(userdata.data(), 0755) != 0) {
// If directory creation failed
......
......@@ -1779,10 +1779,9 @@ std::string ManagerImpl::createConfigFile() const
std::string configdir = std::string(HOMEDIR) + DIR_SEPARATOR_STR +
".config" + DIR_SEPARATOR_STR + PACKAGE;
if (XDG_CONFIG_HOME != NULL) {
std::string xdg_env(XDG_CONFIG_HOME);
if (not xdg_env.empty())
configdir = xdg_env;
std::string xdg_env(XDG_CONFIG_HOME);
if (not xdg_env.empty()) {
configdir = xdg_env;
}
if (mkdir(configdir.data(), 0700) != 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment