Skip to content

Commit

Permalink
system: In resolve command, check that found element is a file
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Jul 19, 2023
1 parent a8caa50 commit 7d81070
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/core/opamSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,11 @@ let t_resolve_command =
else fun f ->
try
let open Unix in
let uid = geteuid () in
let {st_uid; st_gid; st_perm; st_kind; _} = stat f in
if st_kind <> Unix.S_REG then false else
let groups = OpamStd.IntSet.of_list (getegid () :: Array.to_list (getgroups ())) in
let {st_uid; st_gid; st_perm; _} = stat f in
let mask =
if uid = st_uid then
if geteuid () = st_uid then
0o100
else if OpamStd.IntSet.mem st_gid groups then
0o010
Expand Down Expand Up @@ -488,9 +488,12 @@ let t_resolve_command =
name ^ ".exe"
else name
in
let possibles = OpamStd.List.filter_map (fun path ->
let candidate = Filename.concat path name in
if Sys.file_exists candidate then Some candidate else None) path
let possibles =
OpamStd.List.filter_map (fun path ->
let candidate = Filename.concat path name in
if Sys.file_exists candidate && not (Sys.is_directory candidate) then
Some candidate else None)
path
in
match List.find check_perms possibles with
| cmdname -> `Cmd cmdname
Expand Down
6 changes: 2 additions & 4 deletions tests/reftests/core-system.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ system
### mkdir -p bin/echo
### PATH=$BASEDIR/bin/:${PATH}
### opam exec -- echo system
Fatal error: exception ${OPAM}: "execvpe" failed on ${BASEDIR}/bin/echo: Permission denied
# Return code 2 #
system
### opam exec --no-switch -- echo system
Fatal error: exception ${OPAM}: "execvpe" failed on ${BASEDIR}/bin/echo: Permission denied
# Return code 2 #
system
### :I:c: is not executable
### rm -rf bin/echo
### <bin/echo>
Expand Down

0 comments on commit 7d81070

Please sign in to comment.