Skip to content
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

Open
wants to merge 1 commit into
base: msys2-v6.0.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/pacman/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ static int search_path(char **filename, struct stat *bufptr)
path[--plen] = '\0';
}

fullname = malloc(plen + flen + 2);
#ifdef __MSYS__
/* Reserve 4 additional bytes for a potential ".exe" extension */
fullname = malloc(plen + 1 + flen + 4 + 1);
#else
fullname = malloc(plen + 1 + flen + 1);
#endif
if(!fullname) {
free(envpath);
return -1;
Expand All @@ -70,6 +75,26 @@ static int search_path(char **filename, struct stat *bufptr)

if(lstat(fullname, bufptr) == 0) {
free(*filename);
#ifdef __MSYS__
/* Make sure the filename is not supposed to have .exe appended
* MSYS lstat tolerates omission, but the ownership check doesn't */
strcat(fullname, ".exe");
struct stat sbExe;
if (lstat(fullname, &sbExe) == 0) {
if (sbExe.st_ino == bufptr->st_ino
&& sbExe.st_dev == bufptr->st_dev) {
/* file is the same with and without .exe suffix
* => .exe suffix probably required for ownership check. */
*filename = fullname;
*bufptr = sbExe;
free(envpath);
return 0;
}
}
/* undo .exe suffix, because there is no such file or it's
* different from the one without .exe suffix. */
fullname[plen + 1 + flen] = '\0';
#endif
*filename = fullname;
free(envpath);
return 0;
Expand Down
Loading