Skip to content

Commit

Permalink
fix crash found by fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoff-it committed Jul 25, 2024
1 parent 4ac3bfe commit 141af2a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn build(b: *std.Build) !void {
.root_source_file = b.path("src/fuzz/afl.zig"),
// .target = b.resolveTargetQuery(.{ .cpu_model = .baseline }),
.target = target,
.optimize = .ReleaseSafe,
.optimize = .Debug,
.single_threaded = true,
});

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.version = "0.1.0",
.dependencies = .{
.@"zig-afl-kit" = .{
.url = "git+https://github.com/kristoff-it/zig-afl-kit#40acb13fc69c155996e34ea06fb651f9389ec2cd",
.url = "git+https://github.com/kristoff-it/zig-afl-kit#f003bfe714f2964c90939fdc940d5993190a66ec",
.hash = "1220f2d8402bb7bbc4786b9c0aad73910929ea209cbd3b063842371d68abfed33c1e",
},
},
Expand Down
6 changes: 4 additions & 2 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub fn next(p: *Parser, code: []const u8) ?Node {

var path_segments: u32 = 0;

// if (p.call_depth == 1) @breakpoint();

while (p.it.next(code)) |tok| switch (p.state) {
.syntax => unreachable,
.start => switch (tok.tag) {
Expand Down Expand Up @@ -87,12 +89,12 @@ pub fn next(p: *Parser, code: []const u8) ?Node {
path_segments += 1;
},
.lparen => {
if (path_segments == 0) {
if (path_segments < 2) {
p.state = .syntax;
return .{ .tag = .syntax_error, .loc = tok.loc };
}

// roll back to get a a lparen
// rewind to get a a lparen
p.it.idx -= 1;
p.state = .call_begin;
if (path_segments > 1) {
Expand Down
1 change: 1 addition & 0 deletions src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ pub fn VM(
}),
.call => {
// std.debug.assert(vm.stack.len > 0);
// @breakpoint();
if (vm.stack.len == 0) {
vm.reset();
return .{
Expand Down

0 comments on commit 141af2a

Please sign in to comment.