From c0d8edeb5acfe19bb656c65eb428519e5ca7b71c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 17 Feb 2021 20:21:14 +0100 Subject: [PATCH] conf: improve state directory access checks We only need RW permission on the last directory. --- src/pipewire/conf.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pipewire/conf.c b/src/pipewire/conf.c index dc88e80dc..aaec846a4 100644 --- a/src/pipewire/conf.c +++ b/src/pipewire/conf.c @@ -106,7 +106,7 @@ static int get_read_path(char *path, size_t size, const char *prefix, const char static int ensure_path(char *path, int size, const char *paths[]) { - int i, len, res; + int i, len, res, mode; char *p = path; for (i = 0; paths[i] != NULL; i++) { @@ -119,14 +119,18 @@ static int ensure_path(char *path, int size, const char *paths[]) p += len; size -= len; - if ((res = access(path, R_OK | W_OK | X_OK)) < 0) { + mode = X_OK; + if (paths[i+1] == NULL) + mode |= R_OK | W_OK; + + if ((res = access(path, mode)) < 0) { if (errno != ENOENT) return -errno; if ((res = mkdir(path, 0700)) < 0) { pw_log_info("Can't create directory %s: %m", path); return -errno; } - if ((res = access(path, R_OK | W_OK | X_OK)) < 0) + if ((res = access(path, mode)) < 0) return -errno; pw_log_info("created directory %s", path);