From d9d450292d6167a167ff420b64e57f2a46a61cf6 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 10 Mar 2021 12:26:11 -0700 Subject: [PATCH] Remove compatibility defines for POSIX sys/stat.h macros. Modern systems have them and we no longer support pre-POSIX systems. This fixes potential redefinition of the macros if sys/stat.h is included after sudo_compat.h. Bug #968. --- include/sudo_compat.h | 42 +++--------------------------------------- lib/util/secure_path.c | 6 +++--- 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 29fdc8578..4ee5b6818 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -146,48 +146,12 @@ # endif #endif -/* - * POSIX versions for those without... - */ -#ifndef _S_IFMT -# define _S_IFMT S_IFMT -#endif /* _S_IFMT */ -#ifndef _S_IFREG -# define _S_IFREG S_IFREG -#endif /* _S_IFREG */ -#ifndef _S_IFDIR -# define _S_IFDIR S_IFDIR -#endif /* _S_IFDIR */ -#ifndef _S_IFLNK -# define _S_IFLNK S_IFLNK -#endif /* _S_IFLNK */ -#ifndef _S_IFIFO -# define _S_IFIFO S_IFIFO -#endif /* _S_IFIFO */ -#ifndef S_ISREG -# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -#endif /* S_ISREG */ -#ifndef S_ISDIR -# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -#endif /* S_ISDIR */ -#ifndef S_ISLNK -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) -#endif /* S_ISLNK */ -#ifndef S_ISFIFO -# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) -#endif /* S_ISLNK */ -#ifndef S_ISTXT -# define S_ISTXT 0001000 -#endif /* S_ISTXT */ - -/* - * ACCESSPERMS (00777) and ALLPERMS (07777) are handy BSDisms - */ +/* ACCESSPERMS and ALLPERMS are handy BSDisms. */ #ifndef ACCESSPERMS -# define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) +# define ACCESSPERMS 00777 #endif /* ACCESSPERMS */ #ifndef ALLPERMS -# define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) +# define ALLPERMS 07777 #endif /* ALLPERMS */ /* For futimens() and utimensat() emulation. */ diff --git a/lib/util/secure_path.c b/lib/util/secure_path.c index 1d2c97d17..639425fbe 100644 --- a/lib/util/secure_path.c +++ b/lib/util/secure_path.c @@ -41,7 +41,7 @@ sudo_secure_path(const char *path, unsigned int type, uid_t uid, gid_t gid, stru debug_decl(sudo_secure_path, SUDO_DEBUG_UTIL); if (path != NULL && stat(path, &sb) == 0) { - if ((sb.st_mode & _S_IFMT) != type) { + if ((sb.st_mode & S_IFMT) != type) { ret = SUDO_PATH_BAD_TYPE; } else if (uid != (uid_t)-1 && sb.st_uid != uid) { ret = SUDO_PATH_WRONG_OWNER; @@ -66,7 +66,7 @@ sudo_secure_path(const char *path, unsigned int type, uid_t uid, gid_t gid, stru int sudo_secure_file_v1(const char *path, uid_t uid, gid_t gid, struct stat *sbp) { - return sudo_secure_path(path, _S_IFREG, uid, gid, sbp); + return sudo_secure_path(path, S_IFREG, uid, gid, sbp); } /* @@ -75,5 +75,5 @@ sudo_secure_file_v1(const char *path, uid_t uid, gid_t gid, struct stat *sbp) int sudo_secure_dir_v1(const char *path, uid_t uid, gid_t gid, struct stat *sbp) { - return sudo_secure_path(path, _S_IFDIR, uid, gid, sbp); + return sudo_secure_path(path, S_IFDIR, uid, gid, sbp); }