I’m stuck on something probably really stupid, but basically to explain my use case, I’m rewriting a small fuzzer that I’ve wrote for a project of mine, the fuzzer, takes the path to the program, and some options, to build some inputs, yadi yada, internally I generate the random input, and put it inside of an arraylist, but I can’t find a way to make the argv for the child, or at least when I succeeded It panicked.
pub fn run(self: Self) !bool {
std.log.info("run start\n", .{});
const inputs = self.cmd_buffer.items;
var child_argv: [32][]const u8 = undefined;
var iter = std.mem.tokenizeScalar(u8, inputs, '@');
var i: usize = 0;
while (iter.next()) |arg| : (i += 1){
std.log.info("child_argv[{d}]={s}\n", .{ i, arg });
child_argv[i] = arg;
}
var child = std.process.Child.init(&child_argv, self.allocator);
const handle = try child.spawnAndWait();
std.log.info("run done\n", .{});
return (handle.Exited == 0);
}
❯ zbr -- /home/pollivie/workspace/minishell/minishell
info: parse start
info: parse skip
info: parse arg = /home/pollivie/workspace/minishell/minishell
info: parse arg = is a path
info: build start
info: build done
/home/pollivie/workspace/minishell/minishell@ls << wc > @
info: run start
info: child_argv[0]=/home/pollivie/workspace/minishell/minishell
info: child_argv[1]=ls << wc >
thread 28939 panic: attempt to unwrap error: Overflow
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/math.zig:1242:9: 0x1088e5f in ceilPowerOfTwo__anon_9259 (minishell-fuzzer)
return error.Overflow;
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/math.zig:1251:43: 0x107493f in ceilPowerOfTwoAssert__anon_8311 (minishell-fuzzer)
return ceilPowerOfTwo(T, value) catch unreachable;
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/heap/general_purpose_allocator.zig:803:61: 0x104288e in resize (minishell-fuzzer)
const new_size_class = math.ceilPowerOfTwoAssert(usize, new_aligned_size);
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/mem/Allocator.zig:92:30: 0x1091423 in alloc (minishell-fuzzer)
return self.vtable.resize(self.ptr, buf, log2_buf_align, new_len, ret_addr);
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/mem/Allocator.zig:86:29: 0x1093944 in allocBytesWithAlignment__anon_9380 (minishell-fuzzer)
return self.vtable.alloc(self.ptr, len, ptr_align, ret_addr);
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/mem/Allocator.zig:211:40: 0x107cabd in allocWithSizeAndAlignment__anon_8523 (minishell-fuzzer)
return self.allocBytesWithAlignment(alignment, byte_count, return_address);
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/mem/Allocator.zig:205:75: 0x1048511 in alloc__anon_7347 (minishell-fuzzer)
const ptr: [*]align(a) T = @ptrCast(try self.allocWithSizeAndAlignment(@sizeOf(T), a, n, return_address));
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/mem/Allocator.zig:326:40: 0x108d37f in dupeZ__anon_9332 (minishell-fuzzer)
const new_buf = try allocator.alloc(T, m.len + 1);
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/process/Child.zig:610:65: 0x1078ec7 in spawnPosix (minishell-fuzzer)
for (self.argv, 0..) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr;
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/process/Child.zig:242:31: 0x1045a5c in spawn (minishell-fuzzer)
return self.spawnPosix();
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/process/Child.zig:247:19: 0x103dc4f in spawnAndWait (minishell-fuzzer)
try self.spawn();
^
/home/pollivie/workspace/minishell-fuzzer/src/main.zig:154:50: 0x103d7d3 in run (minishell-fuzzer)
const handle = try child.spawnAndWait();
^
/home/pollivie/workspace/minishell-fuzzer/src/main.zig:181:31: 0x103df41 in main (minishell-fuzzer)
if (try fuzzer.run()) {
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/start.zig:524:37: 0x103cab5 in posixCallMainAndExit (minishell-fuzzer)
const result = root.main() catch |err| {
^
/home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/lib/zig/std/start.zig:266:5: 0x103c5d1 in _start (minishell-fuzzer)
asm volatile (switch (native_arch) {
^
???:?:?: 0x1 in ??? (???)
Unwind information for `???:0x1` was not available, trace may be incomplete
run
└─ run minishell-fuzzer failure
error: the following command terminated unexpectedly:
/home/pollivie/workspace/minishell-fuzzer/zig-out/bin/minishell-fuzzer /home/pollivie/workspace/minishell/minishell
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run minishell-fuzzer failure
error: the following build command failed with exit code 1:
/home/pollivie/workspace/minishell-fuzzer/.zig-cache/o/9949fafc13ff8025c254ae8970ec33bb/build /home/linuxbrew/.linuxbrew/Cellar/zig/0.13.0/bin/zig /home/pollivie/workspace/minishell-fuzzer /home/pollivie/workspace/minishell-fuzzer/.zig-cache /home/pollivie/.cache/zig --seed 0x7bbddf00 -Zf853190b665bcddc run -- /home/pollivie/workspace/minishell/minishell
This is what I get currently ? I’m not sure what I should understand, here there seems to be some alignment problems, but I’m not sure how I can fix it, I’m sure I’m just doing it wrong so if anyone knows a better solution I’m all in.
My intuitions tells me it probably comes from child_argv being declared like [32][]u8
but I’m not sure how to do it differently?