diff options
| author | Antonin Décimo <antonin.decimo@gmail.com> | 2022-03-11 14:08:49 +0100 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2022-06-09 18:34:17 +0000 |
| commit | 9434e8d69f76d7859ed7b18edc5a62450ad8d040 (patch) | |
| tree | 8f5bc37e37479183bc2da284a7444a3b7ac68f8c /src | |
| parent | cursor/os-compatibility: fix trailing space (diff) | |
| download | wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar.gz wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar.bz2 wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar.lz wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar.xz wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.tar.zst wayland-9434e8d69f76d7859ed7b18edc5a62450ad8d040.zip | |
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/wayland-client.c | 4 | ||||
| -rw-r--r-- | src/wayland-server.c | 7 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/wayland-client.c b/src/wayland-client.c index 75692e6..659c132 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -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; diff --git a/src/wayland-server.c b/src/wayland-server.c index 93e42c7..00cfc27 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -1557,8 +1557,9 @@ wl_socket_init_for_display_name(struct wl_socket *s, const char *name) if (name[0] != '/') { runtime_dir = getenv("XDG_RUNTIME_DIR"); - if (!runtime_dir) { - wl_log("error: XDG_RUNTIME_DIR not set in the environment\n"); + if (!runtime_dir || runtime_dir[0] != '/') { + wl_log("error: XDG_RUNTIME_DIR is invalid or not set in" + " the environment\n"); /* to prevent programs reporting * "failed to add socket: Success" */ @@ -1718,7 +1719,7 @@ wl_display_add_socket_fd(struct wl_display *display, int sock_fd) * * If the socket name is a relative path, the Unix socket will be created in * the directory pointed to by environment variable XDG_RUNTIME_DIR. If - * XDG_RUNTIME_DIR is not set, then this function fails and returns -1. + * XDG_RUNTIME_DIR is invalid or not set, then this function fails and returns -1. * * If the socket name is an absolute path, then it is used as-is for the * the Unix socket. |
