-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
bpo-31940: Reject faulty lchown implementations #4267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Detect faulty ``lchmod`` implementation to fix ``shutil.copystat`` on alpine | ||
linux. Patch by Anthony Sottile. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11130,7 +11130,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ | |
futimens futimes gai_strerror getentropy \ | ||
getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ | ||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ | ||
initgroups kill killpg lchmod lchown linkat lstat lutimes mmap \ | ||
initgroups kill killpg lchown linkat lstat lutimes mmap \ | ||
memrchr mbrtowc mkdirat mkfifo \ | ||
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ | ||
posix_fallocate posix_fadvise pread \ | ||
|
@@ -11837,6 +11837,60 @@ $as_echo "#define HAVE_LCHFLAGS 1" >>confdefs.h | |
|
||
fi | ||
|
||
|
||
# on alpine, lchmod raises errno EOPNOTSUPP on symlinks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, technically not just Alpine, it's a musl libc thing. |
||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for broken lchmod" >&5 | ||
$as_echo_n "checking for broken lchmod... " >&6; } | ||
if ${ac_cv_have_lchmod+:} false; then : | ||
$as_echo_n "(cached) " >&6 | ||
else | ||
if test "$cross_compiling" = yes; then : | ||
ac_cv_have_lchmod=cross | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this else for the inner if-block? Should it be indented one level, along with an extra level for the Actually, It looks like there's a ton of nested stuff below that isn't indented -- it makes it hard to read, but I don't know if that is a style thing I'm not used to since I haven't worked specifically in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext | ||
/* end confdefs.h. */ | ||
|
||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
int main(int argc, char*argv[]) | ||
{ | ||
if (symlink(argv[0], "test")) | ||
return 1; | ||
if (lchmod("test", 0777)) | ||
return 1; | ||
return 0; | ||
} | ||
|
||
_ACEOF | ||
if ac_fn_c_try_run "$LINENO"; then : | ||
ac_cv_have_lchmod=yes | ||
else | ||
ac_cv_have_lchmod=no | ||
fi | ||
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ | ||
conftest.$ac_objext conftest.beam conftest.$ac_ext | ||
fi | ||
|
||
|
||
fi | ||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_lchmod" >&5 | ||
$as_echo "$ac_cv_have_lchmod" >&6; } | ||
if test "$ac_cv_have_lchmod" = cross ; then | ||
ac_fn_c_check_func "$LINENO" "lchmod" "ac_cv_func_lchmod" | ||
if test "x$ac_cv_func_lchmod" = xyes; then : | ||
ac_cv_have_lchmod="yes" | ||
else | ||
ac_cv_have_lchmod="no" | ||
fi | ||
|
||
fi | ||
if test "$ac_cv_have_lchmod" = yes ; then | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra newlines for a reason? Also, not indented? |
||
$as_echo "#define HAVE_LCHMOD 1" >>confdefs.h | ||
|
||
fi | ||
rm -f test | ||
|
||
case $ac_sys_system/$ac_sys_release in | ||
Darwin/*) | ||
_CUR_CFLAGS="${CFLAGS}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3405,7 +3405,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ | |
futimens futimes gai_strerror getentropy \ | ||
getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ | ||
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ | ||
initgroups kill killpg lchmod lchown linkat lstat lutimes mmap \ | ||
initgroups kill killpg lchown linkat lstat lutimes mmap \ | ||
memrchr mbrtowc mkdirat mkfifo \ | ||
mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ | ||
posix_fallocate posix_fadvise pread \ | ||
|
@@ -3600,6 +3600,30 @@ if test "$ac_cv_have_lchflags" = yes ; then | |
AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.]) | ||
fi | ||
|
||
|
||
# on alpine, lchmod raises errno EOPNOTSUPP on symlinks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another mention of just Alpine, same suggestion as above. |
||
AC_CACHE_CHECK([for broken lchmod], [ac_cv_have_lchmod], [dnl | ||
AC_RUN_IFELSE([AC_LANG_SOURCE([[ | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
int main(int argc, char*argv[]) | ||
{ | ||
if (symlink(argv[0], "test")) | ||
return 1; | ||
if (lchmod("test", 0777)) | ||
return 1; | ||
return 0; | ||
} | ||
]])],[ac_cv_have_lchmod=yes],[ac_cv_have_lchmod=no],[ac_cv_have_lchmod=cross]) | ||
]) | ||
if test "$ac_cv_have_lchmod" = cross ; then | ||
AC_CHECK_FUNC([lchmod], [ac_cv_have_lchmod="yes"], [ac_cv_have_lchmod="no"]) | ||
fi | ||
if test "$ac_cv_have_lchmod" = yes ; then | ||
AC_DEFINE(HAVE_LCHMOD, 1, [Define to 1 if you have the `lchmod' function.]) | ||
fi | ||
rm -f test | ||
|
||
dnl Check if system zlib has *Copy() functions | ||
dnl | ||
dnl On MacOSX the linker will search for dylibs on the entire linker path | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to say "on Alpine linux and other distributions using musl libc", because the issue is actually related to the musl implementation, I believe. This affects me on Gentoo+musl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I did hit this on gentoo musl as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh shoot, I totally forgot about this patch -- I need to revive my other approach 😨