Skip to content

Commit

Permalink
Merge pull request #5714 from dra27/harden-docker
Browse files Browse the repository at this point in the history
Harden `windows_get_shell`
  • Loading branch information
kit-ty-kate authored Nov 13, 2023
2 parents f8ea5e0 + 9ec78ae commit 05915bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ users)
## Internal

## Internal: Windows
* Fix sporadic crash and segfault in shell detection (seen in native containers) [#5714 @dra27]

## Test

Expand Down Expand Up @@ -159,3 +160,4 @@ users)
* `OpamSystem.mk_temp_dir`: resolve real path with `OpamSystem.real_path` before returning it [#5654 @rjbou]
* `OpamSystem.resolve_command`: in command resolution path, check that the file is not a directory and that it is a regular file [#5606 @rjbou - fix #5585 #5597 #5650 #5626]
* `OpamStd.Config.env_level`: fix level parsing, it was inverted (eg, "no" gives level 1, and "yes" level 0) [#5686 @smorimoto]
* `OpamStd.Sys.chop_exe_suffix`: removes `.exe` from the end of a path, if present
6 changes: 5 additions & 1 deletion src/core/opamStd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,9 @@ module OpamSys = struct
else
fun x -> x

let chop_exe_suffix name =
Option.default name (Filename.chop_suffix_opt name ~suffix:".exe")

let windows_process_ancestry = Lazy.from_fun OpamStubs.getProcessAncestry

type shell_choice = Accept of shell
Expand All @@ -1085,10 +1088,11 @@ module OpamSys = struct
| "pwsh.exe" -> Some (Accept (SH_pwsh Powershell_pwsh))
| "cmd.exe" -> Some (Accept SH_cmd)
| "env.exe" -> Some (Accept SH_sh)
| "" -> None
| name ->
Option.map
(fun shell -> Accept shell)
(shell_of_string (Filename.chop_suffix name ".exe"))
(shell_of_string (chop_exe_suffix name))
in
lazy (
let lazy ancestors = windows_process_ancestry in
Expand Down
3 changes: 3 additions & 0 deletions src/core/opamStd.mli
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ module Sys : sig
(** Append .exe (only if missing) to executable filenames on Windows *)
val executable_name : string -> string

(** Remove .exe (if present) from an executable filename on Windows *)
val chop_exe_suffix : string -> string

(** The different families of shells we know about *)
type powershell_host = Powershell_pwsh | Powershell
type shell = SH_sh | SH_bash | SH_zsh | SH_csh | SH_fish
Expand Down
3 changes: 2 additions & 1 deletion src/stubs/win32/opamWindows.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,14 @@ CAMLprim value OPAMW_GetProcessAncestry(value unit)
read_entry = FALSE;
break;
} else {
cur = ptr + (cur - processes);
processes = ptr;
}
}
cur->LowPart = entry.th32ProcessID;
cur->HighPart = entry.th32ParentProcessID;
cur[1].QuadPart = 0LL;
if (cur->LowPart == target) {
cur[1].QuadPart = 0LL;
break;
} else {
cur++;
Expand Down

0 comments on commit 05915bc

Please sign in to comment.