summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-05-14 13:08:32 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2018-05-14 13:08:32 +0200
commit9753b302c16af045d176d21b1b00a7de08943804 (patch)
tree211ff79b5a0668b3fcb5bd9d69d381fc98189924
parente9cd559cf0190cce630f62bc3fbcd32834873476 (diff)
downloadpoezio-9753b302c16af045d176d21b1b00a7de08943804.tar.gz
poezio-9753b302c16af045d176d21b1b00a7de08943804.tar.bz2
poezio-9753b302c16af045d176d21b1b00a7de08943804.tar.xz
poezio-9753b302c16af045d176d21b1b00a7de08943804.zip
config: Reject relative XDG basedir paths.
-rw-r--r--poezio/config.py14
1 files changed, 7 insertions, 7 deletions
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)