-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
bpo-31940: Reject faulty lchmod implementations #4783
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 musl | ||
| libc. Patch by Anthony Sottile. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2814,6 +2814,9 @@ os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, | |
| #ifdef HAVE_FCHMODAT | ||
| int fchmodat_nofollow_unsupported = 0; | ||
| #endif | ||
| #ifdef HAVE_LCHMOD | ||
| int lchmod_unsupported = 0; | ||
| #endif | ||
|
|
||
| #if !(defined(HAVE_FCHMODAT) || defined(HAVE_LCHMOD)) | ||
| if (follow_symlinks_specified("chmod", follow_symlinks)) | ||
|
|
@@ -2845,8 +2848,16 @@ os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, | |
| else | ||
| #endif | ||
| #ifdef HAVE_LCHMOD | ||
| if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD)) | ||
| if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD)) { | ||
| result = lchmod(path->narrow, mode); | ||
| /* | ||
| * similar to the comment below about fchmodat(), some platforms | ||
| * (for instance musl libc) do not ship a functional lchmod(). | ||
| */ | ||
| lchmod_unsupported = | ||
| result && | ||
| ((errno == ENOTSUP) || (errno == EOPNOTSUPP)); | ||
|
Member
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. Oh, there are two different error codes? Which one is raised on muslc?
Contributor
Author
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. muslc raises |
||
| } | ||
| else | ||
| #endif | ||
| #ifdef HAVE_FCHMODAT | ||
|
|
@@ -2888,6 +2899,12 @@ os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd, | |
| return NULL; | ||
| } | ||
| else | ||
| #endif | ||
| #ifdef HAVE_LCHMOD | ||
| if (lchmod_unsupported) { | ||
| follow_symlinks_specified("chmod", follow_symlinks); | ||
| return NULL; | ||
| } else | ||
| #endif | ||
| return path_error(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.
Should this be
mkstemp?mktempseems to be deprecated.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.
This was copied from adjacent test (in the original PR). It's not exactly that
mktempis deprecated, it's that it's insecure. However in this case, the same security problem would exist since it's essentially:mkstempmkstempmkstempThere's a race between 2 and 3 where something could create a file
Fortunately it doesn't really matter since it's just a test.