std: fix memory bug in getExternalExecutor

Until now, we would pass `candidate: NativeTargetInfo` which creates
a copy of the `NativeTargetInfo.DynamicLinker` buffer. We would then
return this buffer in `bad_dl: []const u8` which would goes out-of-scope
the moment we leave this function frame yielding garbage. To fix this,
we just need to remember to pass by const-pointer
`candidate: *const NativeTargetInfo`.
This commit is contained in:
Jakub Konka 2023-10-06 12:42:58 +02:00
parent e6590fea19
commit df9462690f
4 changed files with 6 additions and 6 deletions

View file

@ -679,7 +679,7 @@ fn runCommand(
}
const need_cross_glibc = exe.target.isGnuLibC() and exe.is_linking_libc;
switch (b.host.getExternalExecutor(exe.target_info, .{
switch (b.host.getExternalExecutor(&exe.target_info, .{
.qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null,
.link_libc = exe.is_linking_libc,
})) {

View file

@ -1002,7 +1002,7 @@ pub const GetExternalExecutorOptions = struct {
/// of the other target.
pub fn getExternalExecutor(
host: NativeTargetInfo,
candidate: NativeTargetInfo,
candidate: *const NativeTargetInfo,
options: GetExternalExecutorOptions,
) Executor {
const os_match = host.target.os.tag == candidate.target.os.tag;

View file

@ -3667,7 +3667,7 @@ fn buildOutputType(
test_exec_args.items,
self_exe_path.?,
arg_mode,
target_info,
&target_info,
&comp_destroyed,
all_args,
runtime_args_start,
@ -3995,7 +3995,7 @@ fn runOrTest(
test_exec_args: []const ?[]const u8,
self_exe_path: []const u8,
arg_mode: ArgMode,
target_info: std.zig.system.NativeTargetInfo,
target_info: *const std.zig.system.NativeTargetInfo,
comp_destroyed: *bool,
all_args: []const []const u8,
runtime_args_start: ?usize,
@ -6256,7 +6256,7 @@ fn parseIntSuffix(arg: []const u8, prefix_len: usize) u64 {
fn warnAboutForeignBinaries(
arena: Allocator,
arg_mode: ArgMode,
target_info: std.zig.system.NativeTargetInfo,
target_info: *const std.zig.system.NativeTargetInfo,
link_libc: bool,
) !void {
const host_cross_target: std.zig.CrossTarget = .{};

View file

@ -590,7 +590,7 @@ pub fn lowerToBuildSteps(
const run = if (case.target.ofmt == .c) run_step: {
const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err|
std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)});
if (host.getExternalExecutor(target_info, .{ .link_libc = true }) != .native) {
if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) {
// We wouldn't be able to run the compiled C code.
break :no_exec;
}