mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
core-util: ensure that we chmod only the dir we ourselves created
This commit is contained in:
parent
abb05d610d
commit
87fdbb544b
2 changed files with 35 additions and 6 deletions
|
|
@ -439,7 +439,7 @@ AC_CHECK_FUNCS_ONCE([lrintf strtof])
|
||||||
AC_FUNC_FORK
|
AC_FUNC_FORK
|
||||||
AC_FUNC_GETGROUPS
|
AC_FUNC_GETGROUPS
|
||||||
AC_FUNC_SELECT_ARGTYPES
|
AC_FUNC_SELECT_ARGTYPES
|
||||||
AC_CHECK_FUNCS_ONCE([chmod chown clock_gettime getaddrinfo getgrgid_r getgrnam_r \
|
AC_CHECK_FUNCS_ONCE([chmod chown fstat fchown fchmod clock_gettime getaddrinfo getgrgid_r getgrnam_r \
|
||||||
getpwnam_r getpwuid_r gettimeofday getuid inet_ntop inet_pton mlock nanosleep \
|
getpwnam_r getpwuid_r gettimeofday getuid inet_ntop inet_pton mlock nanosleep \
|
||||||
pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \
|
pipe posix_fadvise posix_madvise posix_memalign setpgid setsid shm_open \
|
||||||
sigaction sleep sysconf pthread_setaffinity_np])
|
sigaction sleep sysconf pthread_setaffinity_np])
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ void pa_make_fd_cloexec(int fd) {
|
||||||
/** Creates a directory securely */
|
/** Creates a directory securely */
|
||||||
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
|
int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int r, saved_errno;
|
int r, saved_errno, fd;
|
||||||
|
|
||||||
pa_assert(dir);
|
pa_assert(dir);
|
||||||
|
|
||||||
|
|
@ -217,16 +217,45 @@ int pa_make_secure_dir(const char* dir, mode_t m, uid_t uid, gid_t gid) {
|
||||||
if (r < 0 && errno != EEXIST)
|
if (r < 0 && errno != EEXIST)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef HAVE_CHOWN
|
#ifdef HAVE_FSTAT
|
||||||
|
if ((fd = open(dir,
|
||||||
|
#ifdef O_CLOEXEC
|
||||||
|
O_CLOEXEC|
|
||||||
|
#endif
|
||||||
|
#ifdef O_NOCTTY
|
||||||
|
O_NOCTTY|
|
||||||
|
#endif
|
||||||
|
#ifdef O_NOFOLLOW
|
||||||
|
O_NOFOLLOW|
|
||||||
|
#endif
|
||||||
|
O_RDONLY)) < 0)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (fstat(fd, &st) < 0) {
|
||||||
|
pa_assert_se(pa_close(fd) >= 0);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!S_ISDIR(st.st_mode)) {
|
||||||
|
pa_assert_se(pa_close(fd) >= 0);
|
||||||
|
errno = EEXIST;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_FCHOWN
|
||||||
if (uid == (uid_t)-1)
|
if (uid == (uid_t)-1)
|
||||||
uid = getuid();
|
uid = getuid();
|
||||||
if (gid == (gid_t)-1)
|
if (gid == (gid_t)-1)
|
||||||
gid = getgid();
|
gid = getgid();
|
||||||
(void) chown(dir, uid, gid);
|
(void) fchown(fd, uid, gid);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_CHMOD
|
#ifdef HAVE_FCHMOD
|
||||||
chmod(dir, m);
|
(void) fchmod(fd, m);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
pa_assert_se(pa_close(fd) >= 0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LSTAT
|
#ifdef HAVE_LSTAT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue