From b4b5c2188f9d574b8ddb05355d030f530b165cb2 Mon Sep 17 00:00:00 2001 From: Tanner Bruce Date: Thu, 8 Oct 2015 21:44:38 -0500 Subject: [PATCH] Check that $XDG_RUNTIME_DIR is valid and accessible Signed-off-by: David Adam --- src/env_universal_common.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index d5d14378a..c67fa4150 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -147,7 +147,12 @@ static wcstring get_runtime_path() { wcstring result; const char *dir = getenv("XDG_RUNTIME_DIR"); - if (dir != NULL) + + // Check that the path is actually usable + // Technically this is guaranteed by the fdo spec but in practice + // it is not always the case: see #1828 and #2222 + int mode = R_OK | W_OK | X_OK; + if (dir != NULL && access(dir, mode) == 0 && check_runtime_path(dir) == 0) { result = str2wcstring(dir); }