Skip to content

Commit

Permalink
path-unix: only accept absolute paths
Browse files Browse the repository at this point in the history
The XDG Base Directory specification says “All paths set in these
environment variables must be absolute. If an implementation encounters
a relative path in any of these variables it should consider the path
invalid and ignore it.”
  • Loading branch information
linkmauve committed Aug 26, 2023
1 parent 32be726 commit 1f6c65f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions osdep/path-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ static void path_init(void)
char *xdg_state = getenv("XDG_STATE_HOME");

bool err = false;
if (xdg_config && xdg_config[0]) {
if (xdg_config && xdg_config[0] == '/') {
err = err || MKPATH(mpv_home, "%s/mpv", xdg_config);
} else if (home && home[0]) {
} else if (home && home[0] == '/') {
err = err || MKPATH(mpv_home, "%s/.config/mpv", home);
}

// Maintain compatibility with old ~/.mpv
if (home && home[0])
if (home && home[0] == '/')
err = err || MKPATH(old_home, "%s/.mpv", home);

if (xdg_cache && xdg_cache[0]) {
if (xdg_cache && xdg_cache[0] == '/') {
err = err || MKPATH(mpv_cache, "%s/mpv", xdg_cache);
} else if (home && home[0]) {
} else if (home && home[0] == '/') {
err = err || MKPATH(mpv_cache, "%s/.cache/mpv", home);
}

if (xdg_state && xdg_state[0]) {
if (xdg_state && xdg_state[0] == '/') {
err = err || MKPATH(mpv_state, "%s/mpv", xdg_state);
} else if (home && home[0]) {
} else if (home && home[0] == '/') {
err = err || MKPATH(mpv_state, "%s/.local/state/mpv", home);
}

Expand Down

0 comments on commit 1f6c65f

Please sign in to comment.