-
Notifications
You must be signed in to change notification settings - Fork 13
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
Fix executable file ownership check #37
base: msys2-v6.0.2
Are you sure you want to change the base?
Conversation
Any feedback on this? This is a fix/improvement that I would personally love to see merged. It fixes the primary use of Is there anything I could do to get this accepted? I'm fully prepared to take care of the MSYS2-packages pull request if this is accepted! |
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 does only handle pacman -Qo ntldd
and not pacman -Qo /ucrt64/bin/ntldd
, right?
src/pacman/query.c
Outdated
strcat(fullname, ".exe"); | ||
struct stat sbExe; | ||
if (lstat(fullname, &sbExe) == 0) { | ||
if (sbExe.st_ino == bufptr->st_ino) { |
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.
nitpick, st_dev needs to also be the same
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.
Fixed!
src/pacman/query.c
Outdated
@@ -70,6 +73,32 @@ static int search_path(char **filename, struct stat *bufptr) | |||
|
|||
if(lstat(fullname, bufptr) == 0) { | |||
free(*filename); | |||
|
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.
Please guard all changes via #ifdef __MSYS__
so on Linux the original behavior is used.
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.
Done.
When checking ownership for a command in the system PATH, potentially append a .exe file extension. MSYS itself tolerates omission, but pacman would be unable to identify the command owner without the "correct" path. This is not done if distinct files exist (with/without .exe).
581db4e
to
993a36f
Compare
Thats correct. Right now the changes should be least-intrusive; I believe I would need either two additional lstats for every queried file, or to retry failed ownership checks (with .exe). edit: Currently only queries that do PATH lookup anyway are affected Maybe my performance-concerns are completely misguided here, and I should just make the Thanks for the review! |
If we check ownership for a file we find in
the system PATH then we might need a .exe suffix
on the full path we identified, because although
MSYS will confirm the files existence even if the
suffix is missing, we need the "correct" path
for the actual ownership check.
See issue #36 for details.
Examples
This used to fail:
Fully specifying the executable name still works:
"Correct" file is checked if there is a wrapper AND an exe file with the same name:
Ownership check fails if an exe extension is erroneously specified (no xzcmp.exe exists):
Performance impact should be negligible; this has no effect if there is any path separator in the query, and the worstcase is basically an additional lstat call.