Check that XDG base directories paths are absolute

The [spec][1] reads:

> 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.

and

> If $XDG_DATA_HOME is either not set or empty, a default equal to
> $HOME/.local/share should be used.

Testing that the path is absolute also entails that is is non-empty.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
This commit is contained in:
Antonin Décimo 2022-03-11 14:08:49 +01:00 committed by Simon Ser
parent f710d01663
commit 9434e8d69f
8 changed files with 13 additions and 12 deletions

View file

@ -1076,8 +1076,8 @@ connect_to_socket(const char *name)
path_is_absolute = name[0] == '/';
runtime_dir = getenv("XDG_RUNTIME_DIR");
if (!runtime_dir && !path_is_absolute) {
wl_log("error: XDG_RUNTIME_DIR not set in the environment.\n");
if (((!runtime_dir || runtime_dir[0] != '/') && !path_is_absolute)) {
wl_log("error: XDG_RUNTIME_DIR is invalid or not set in the environment.\n");
/* to prevent programs reporting
* "failed to create display: Success" */
errno = ENOENT;