Skip to content

Fix error 126 by registering DLL search directory for Windows PowerSh… - #366

Merged
johnmccrae merged 2 commits into
18-Stablefrom
jfm/18-stable-error126-hardening
Sep 8, 2026
Merged

Fix error 126 by registering DLL search directory for Windows PowerSh…#366
johnmccrae merged 2 commits into
18-Stablefrom
jfm/18-stable-error126-hardening

Conversation

@johnmccrae

Copy link
Copy Markdown
Contributor

…ell paths

Backport of main commit f9c0fb4 (CHEF-37610, #364).

Windows' default LoadLibrary(Ex) search order used by FFI does not include the directory of the DLL being loaded, so native VC++ runtime dependencies (vcruntime140.dll, msvcp140.dll, etc.) living alongside Chef.PowerShell.Wrapper.dll / Chef.PowerShell.Wrapper.Core.dll could fail to resolve with error 126 even though the wrapper DLL itself loaded fine via its absolute path.

Adds a shared ChefPowerShell::Kernel32 FFI module (SetDefaultDllDirectories/ AddDllDirectory/SetDllDirectoryA) and registers the resolved bin directories before executing, for both the Windows PowerShell (.NET Framework 4.8.1) and pwsh (.NET Core) code paths. Adapted to this branch's existing resolve_wrapper_dll/resolve_core_wrapper_dll DLL resolution instead of main's ChefPowerShell.bin_dir helper, which does not exist on 18-Stable.

Description

Related Issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

…ell paths

Backport of main commit f9c0fb4 (CHEF-37610, #364).

Windows' default LoadLibrary(Ex) search order used by FFI does not
include the directory of the DLL being loaded, so native VC++ runtime
dependencies (vcruntime140.dll, msvcp140.dll, etc.) living alongside
Chef.PowerShell.Wrapper.dll / Chef.PowerShell.Wrapper.Core.dll could
fail to resolve with error 126 even though the wrapper DLL itself
loaded fine via its absolute path.

Adds a shared ChefPowerShell::Kernel32 FFI module (SetDefaultDllDirectories/
AddDllDirectory/SetDllDirectoryA) and registers the resolved bin directories
before executing, for both the Windows PowerShell (.NET Framework 4.8.1) and
pwsh (.NET Core) code paths. Adapted to this branch's existing
resolve_wrapper_dll/resolve_core_wrapper_dll DLL resolution instead of
main's ChefPowerShell.bin_dir helper, which does not exist on 18-Stable.

Signed-off-by: John McCrae <mccrae@progress.com>
Signed-off-by: John McCrae <mccrae@progress.com>
@johnmccrae
johnmccrae merged commit 2daeb64 into 18-Stable Sep 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants