Skip to content

fix(frida): propagate cc's environment when building the test harness - #3927

Open
kkuehl wants to merge 2 commits into
AFLplusplus:mainfrom
kkuehl:kkuehl/libafl-frida-cc-env
Open

kkuehl wants to merge 2 commits into
AFLplusplus:mainfrom
kkuehl:kkuehl/libafl-frida-cc-env

Conversation

@kkuehl

@kkuehl kkuehl commented Sep 30, 2026

Copy link
Copy Markdown

Problem

crates/libafl_frida/build.rs invokes cl.exe directly to link test_harness.dll, but only forwards compiler.args() from the cc crate and drops compiler.env():

let compiler = cc::Build::new().cpp(true).file("test_harness.cpp").get_compiler();
let mut cmd = std::process::Command::new(compiler.path());
let cmd = cmd.args(compiler.args())... // compiler.env() is never applied

Outside a Visual Studio developer shell the process environment has no INCLUDE/LIB, so on Windows the build fails:

test_harness.cpp(1): fatal error C1034: stdint.h: no include path set

This forces Windows consumers of libafl_frida to build from a vcvars-initialised shell, even though cc itself locates MSVC without one (it compiles src/gettls.c fine in the same build).

Fix

cc already resolves the MSVC toolchain (vswhere/registry) and exposes the environment it would use via Tool::env() (pub fn env(&self) -> &[(OsString, OsString)]). Forward it to the direct cl.exe invocation:

.envs(compiler.env().iter().map(|(key, value)| (key, value)))

Verification

Built a Windows consumer (x86_64-pc-windows-msvc) of this crate from a plain PowerShell — no vcvars:

  • before: test_harness.cpp(1): fatal error C1034: stdint.h: no include path set
  • after: test_harness.dll is produced and the crate links successfully

No behavioural change on Unix; the extra environment is empty there.

`libafl_frida/build.rs` invokes `cl.exe` directly to link `test_harness.dll`
but only forwards `compiler.args()` from `cc`, dropping `compiler.env()`.
Outside a Visual Studio developer shell the environment has no
`INCLUDE`/`LIB`, so a Windows build fails with:

    test_harness.cpp(1): fatal error C1034: stdint.h: no include path set

`cc` already resolves the MSVC toolchain on its own (vswhere/registry) and
exposes the resulting environment via `Tool::env()`. Forward it to the
command so `cargo build` works from a plain shell.

Verified on Windows by building a consumer of this crate from a plain
PowerShell (no vcvars): `test_harness.dll` is now produced and links
successfully, where it previously failed with C1034.
The libafl-fuzz fuzzer denies `clippy::all`, and clippy 1.98 flags the
late-initialized `let scheduler;` (`needless_late_init`), failing the
`forkserver/libafl-fuzz` CI job. Build the scheduler in a single
`if`/`else` expression instead.
@kkuehl

kkuehl commented Sep 30, 2026

Copy link
Copy Markdown
Author

The orkserver/libafl-fuzz CI failure is unrelated to this change: that fuzzer has #![deny(clippy::all)] and clippy 1.98 flags the late-initialized let scheduler; in uzzers/forkserver/libafl-fuzz/src/fuzzer.rs (
eedless_late_init) on current main.

I cherry-picked the same fix from #3926 (2f62ce0 -> �9c13de1) so this PR is green standalone. Once #3926 lands, this commit becomes a no-op.

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.

1 participant