From 9753b302c16af045d176d21b1b00a7de08943804 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 14 May 2018 13:08:32 +0200 Subject: config: Reject relative XDG basedir paths. --- poezio/config.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'poezio/config.py') diff --git a/poezio/config.py b/poezio/config.py index a3f974e1..22662c13 100644 --- a/poezio/config.py +++ b/poezio/config.py @@ -21,6 +21,7 @@ import pkg_resources from configparser import RawConfigParser, NoOptionError, NoSectionError from os import environ, makedirs, path, remove from shutil import copy2 +from pathlib import Path from poezio.args import parse_args DEFAULT_CONFIG = { @@ -508,7 +509,7 @@ def check_create_config_dir(): create the configuration directory if it doesn't exist """ config_home = environ.get("XDG_CONFIG_HOME") - if not config_home: + if config_home is None or not Path(config_home).is_absolute(): config_home = path.join(environ.get('HOME'), '.config') CONFIG_PATH = path.join(config_home, 'poezio') @@ -526,7 +527,7 @@ def check_create_cache_dir(): """ global CACHE_DIR cache_home = environ.get("XDG_CACHE_HOME") - if not cache_home: + if cache_home is None or not Path(cache_home).is_absolute(): cache_home = path.join(environ.get('HOME'), '.cache') CACHE_DIR = path.join(cache_home, 'poezio') @@ -618,12 +619,11 @@ def check_create_log_dir(): if not LOG_DIR: - data_dir = environ.get('XDG_DATA_HOME') - if not data_dir: - home = environ.get('HOME') - data_dir = path.join(home, '.local', 'share') + data_home = environ.get('XDG_DATA_HOME') + if data_home is None or not Path(data_home).is_absolute(): + data_home = path.join(environ.get('HOME'), '.local', 'share') - LOG_DIR = path.join(data_dir, 'poezio', 'logs') + LOG_DIR = path.join(data_home, 'poezio', 'logs') LOG_DIR = path.expanduser(LOG_DIR) -- cgit v1.2.3