diff --git a/config.h.in b/config.h.in index 203e80bec..a89f527f6 100644 --- a/config.h.in +++ b/config.h.in @@ -213,10 +213,6 @@ don't. */ #undef HAVE_DECL_SSIZE_MAX -/* Define to 1 if you have the declaration of 'SYMLOOP_MAX', and to 0 if you - don't. */ -#undef HAVE_DECL_SYMLOOP_MAX - /* Define to 1 if you have the declaration of 'sys_sigabbrev', and to 0 if you don't. */ #undef HAVE_DECL_SYS_SIGABBREV @@ -253,10 +249,6 @@ you don't. */ #undef HAVE_DECL__POSIX_PATH_MAX -/* Define to 1 if you have the declaration of '_POSIX_SYMLOOP_MAX', and to 0 - if you don't. */ -#undef HAVE_DECL__POSIX_SYMLOOP_MAX - /* Define to 1 if you have the declaration of '_sys_siglist', and to 0 if you don't. */ #undef HAVE_DECL__SYS_SIGLIST diff --git a/configure b/configure index 4f4c0a663..cd1739905 100755 --- a/configure +++ b/configure @@ -28460,19 +28460,6 @@ else case e in #( esac fi printf "%s\n" "#define HAVE_DECL_SSIZE_MAX $ac_have_decl" >>confdefs.h -ac_fn_check_decl "$LINENO" "SYMLOOP_MAX" "ac_cv_have_decl_SYMLOOP_MAX" " -#include -#include - -" "$ac_c_undeclared_builtin_options" "CFLAGS" -if test "x$ac_cv_have_decl_SYMLOOP_MAX" = xyes -then : - ac_have_decl=1 -else case e in #( - e) ac_have_decl=0 ;; -esac -fi -printf "%s\n" "#define HAVE_DECL_SYMLOOP_MAX $ac_have_decl" >>confdefs.h ac_fn_check_decl "$LINENO" "SIZE_MAX" "ac_cv_have_decl_SIZE_MAX" " #include @@ -28587,25 +28574,6 @@ fi printf "%s\n" "#define HAVE_DECL__POSIX_PATH_MAX $ac_have_decl" >>confdefs.h -fi -if test "$ac_cv_have_decl_SYMLOOP_MAX" != "yes" -then : - - ac_fn_check_decl "$LINENO" "_POSIX_SYMLOOP_MAX" "ac_cv_have_decl__POSIX_SYMLOOP_MAX" " -#include -#include - -" "$ac_c_undeclared_builtin_options" "CFLAGS" -if test "x$ac_cv_have_decl__POSIX_SYMLOOP_MAX" = xyes -then : - ac_have_decl=1 -else case e in #( - e) ac_have_decl=0 ;; -esac -fi -printf "%s\n" "#define HAVE_DECL__POSIX_SYMLOOP_MAX $ac_have_decl" >>confdefs.h - - fi diff --git a/configure.ac b/configure.ac index 4b73de554..0a3cf8017 100644 --- a/configure.ac +++ b/configure.ac @@ -3323,7 +3323,7 @@ AC_INCLUDES_DEFAULT dnl dnl Check for incomplete limits.h and missing SIZE_MAX. dnl -AC_CHECK_DECLS([LLONG_MAX, LLONG_MIN, ULLONG_MAX, PATH_MAX, SSIZE_MAX, SYMLOOP_MAX], [], [], [ +AC_CHECK_DECLS([LLONG_MAX, LLONG_MIN, ULLONG_MAX, PATH_MAX, SSIZE_MAX], [], [], [ #include #include ]) @@ -3369,12 +3369,6 @@ AS_IF([test "$ac_cv_have_decl_PATH_MAX" != "yes"], [ #include ]]) ]) -AS_IF([test "$ac_cv_have_decl_SYMLOOP_MAX" != "yes"], [ - AC_CHECK_DECLS([_POSIX_SYMLOOP_MAX], [], [], [[ -#include -#include - ]]) -]) dnl dnl Check for strsignal() or sys_siglist diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 856f379f6..0996ec7c8 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -103,14 +103,6 @@ # endif #endif -#if defined(HAVE_DECL_SYMLOOP_MAX) && !HAVE_DECL_SYMLOOP_MAX -# if defined(HAVE_DECL__POSIX_SYMLOOP_MAX) && HAVE_DECL__POSIX_SYMLOOP_MAX -# define SYMLOOP_MAX _POSIX_SYMLOOP_MAX -# else -# define SYMLOOP_MAX 8 -# endif -#endif - /* ACCESSPERMS and ALLPERMS are handy BSDisms. */ #ifndef ACCESSPERMS # define ACCESSPERMS 00777 diff --git a/lib/util/realpath.c b/lib/util/realpath.c index 2d4f523a9..fe0f061f0 100644 --- a/lib/util/realpath.c +++ b/lib/util/realpath.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -58,6 +59,7 @@ sudo_realpath(const char *path, char *resolved) int idx = 0, nlnk = 0; const char *q; char *p, wbuf[2][PATH_MAX], *fres = NULL; + static long symloop_max; size_t len; ssize_t n; @@ -66,6 +68,11 @@ sudo_realpath(const char *path, char *resolved) return NULL; } + if (symloop_max == 0) { + if ((symloop_max = sysconf(_SC_SYMLOOP_MAX)) <= 0) + symloop_max = 8; /* POSIX */ + } + if (resolved == NULL) { fres = resolved = malloc(PATH_MAX); if (resolved == NULL) @@ -145,7 +152,7 @@ loop: goto out; } p[0] = '/'; - memcpy(&p[1], path, q - path); + memcpy(&p[1], path, (size_t)(q - path)); p[1 + q - path] = '\0'; /* @@ -156,7 +163,7 @@ loop: goto out; if (S_ISLNK(sb.st_mode)) { - if (nlnk++ >= SYMLOOP_MAX) { + if (nlnk++ >= symloop_max) { errno = ELOOP; goto out; } @@ -169,7 +176,7 @@ loop: } /* Append unresolved path to link target and switch to it. */ - if (n + (len = strlen(q)) + 1 > sizeof(wbuf[0])) { + if ((size_t)n + (len = strlen(q)) + 1 > sizeof(wbuf[0])) { errno = ENAMETOOLONG; goto out; }