realpath.c: include limits.h and use sysconf(_SC_SYMLOOP_MAX)
This is more portable and eliminates the need to check for SYMLOOP_MAX (and provide it if missing) in configure. Also quiet some -Wconversion warnings.
This commit is contained in:
@@ -213,10 +213,6 @@
|
|||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL_SSIZE_MAX
|
#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
|
/* Define to 1 if you have the declaration of 'sys_sigabbrev', and to 0 if you
|
||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL_SYS_SIGABBREV
|
#undef HAVE_DECL_SYS_SIGABBREV
|
||||||
@@ -253,10 +249,6 @@
|
|||||||
you don't. */
|
you don't. */
|
||||||
#undef HAVE_DECL__POSIX_PATH_MAX
|
#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
|
/* Define to 1 if you have the declaration of '_sys_siglist', and to 0 if you
|
||||||
don't. */
|
don't. */
|
||||||
#undef HAVE_DECL__SYS_SIGLIST
|
#undef HAVE_DECL__SYS_SIGLIST
|
||||||
|
32
configure
vendored
32
configure
vendored
@@ -28460,19 +28460,6 @@ else case e in #(
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
printf "%s\n" "#define HAVE_DECL_SSIZE_MAX $ac_have_decl" >>confdefs.h
|
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 <sys/types.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
" "$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" "
|
ac_fn_check_decl "$LINENO" "SIZE_MAX" "ac_cv_have_decl_SIZE_MAX" "
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -28587,25 +28574,6 @@ fi
|
|||||||
printf "%s\n" "#define HAVE_DECL__POSIX_PATH_MAX $ac_have_decl" >>confdefs.h
|
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 <sys/types.h>
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
" "$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
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
@@ -3323,7 +3323,7 @@ AC_INCLUDES_DEFAULT
|
|||||||
dnl
|
dnl
|
||||||
dnl Check for incomplete limits.h and missing SIZE_MAX.
|
dnl Check for incomplete limits.h and missing SIZE_MAX.
|
||||||
dnl
|
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 <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
])
|
])
|
||||||
@@ -3369,12 +3369,6 @@ AS_IF([test "$ac_cv_have_decl_PATH_MAX" != "yes"], [
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
]])
|
]])
|
||||||
])
|
])
|
||||||
AS_IF([test "$ac_cv_have_decl_SYMLOOP_MAX" != "yes"], [
|
|
||||||
AC_CHECK_DECLS([_POSIX_SYMLOOP_MAX], [], [], [[
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <limits.h>
|
|
||||||
]])
|
|
||||||
])
|
|
||||||
|
|
||||||
dnl
|
dnl
|
||||||
dnl Check for strsignal() or sys_siglist
|
dnl Check for strsignal() or sys_siglist
|
||||||
|
@@ -103,14 +103,6 @@
|
|||||||
# endif
|
# endif
|
||||||
#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. */
|
/* ACCESSPERMS and ALLPERMS are handy BSDisms. */
|
||||||
#ifndef ACCESSPERMS
|
#ifndef ACCESSPERMS
|
||||||
# define ACCESSPERMS 00777
|
# define ACCESSPERMS 00777
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -58,6 +59,7 @@ sudo_realpath(const char *path, char *resolved)
|
|||||||
int idx = 0, nlnk = 0;
|
int idx = 0, nlnk = 0;
|
||||||
const char *q;
|
const char *q;
|
||||||
char *p, wbuf[2][PATH_MAX], *fres = NULL;
|
char *p, wbuf[2][PATH_MAX], *fres = NULL;
|
||||||
|
static long symloop_max;
|
||||||
size_t len;
|
size_t len;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
@@ -66,6 +68,11 @@ sudo_realpath(const char *path, char *resolved)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (symloop_max == 0) {
|
||||||
|
if ((symloop_max = sysconf(_SC_SYMLOOP_MAX)) <= 0)
|
||||||
|
symloop_max = 8; /* POSIX */
|
||||||
|
}
|
||||||
|
|
||||||
if (resolved == NULL) {
|
if (resolved == NULL) {
|
||||||
fres = resolved = malloc(PATH_MAX);
|
fres = resolved = malloc(PATH_MAX);
|
||||||
if (resolved == NULL)
|
if (resolved == NULL)
|
||||||
@@ -145,7 +152,7 @@ loop:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
p[0] = '/';
|
p[0] = '/';
|
||||||
memcpy(&p[1], path, q - path);
|
memcpy(&p[1], path, (size_t)(q - path));
|
||||||
p[1 + q - path] = '\0';
|
p[1 + q - path] = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -156,7 +163,7 @@ loop:
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (S_ISLNK(sb.st_mode)) {
|
if (S_ISLNK(sb.st_mode)) {
|
||||||
if (nlnk++ >= SYMLOOP_MAX) {
|
if (nlnk++ >= symloop_max) {
|
||||||
errno = ELOOP;
|
errno = ELOOP;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@@ -169,7 +176,7 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Append unresolved path to link target and switch to it. */
|
/* 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;
|
errno = ENAMETOOLONG;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user