add tests for fuzzed results, clean up unimplemented osc warning

This commit is contained in:
Nameless
2023-10-19 16:38:52 -05:00
parent 81f7ae63b0
commit 49f1866f28
3 changed files with 63 additions and 20 deletions

View File

@ -255,6 +255,9 @@ pub fn expandPath(alloc: Allocator, cmd: []const u8) !?[]u8 {
path_buf[path_len] = 0; path_buf[path_len] = 0;
const full_path = path_buf[0..path_len :0]; const full_path = path_buf[0..path_len :0];
// Skip if this isn't an absolute path
if (!std.fs.path.isAbsolute(full_path)) continue;
// Stat it // Stat it
const f = std.fs.openFileAbsolute(full_path, .{}) catch |err| switch (err) { const f = std.fs.openFileAbsolute(full_path, .{}) catch |err| switch (err) {
error.FileNotFound => continue, error.FileNotFound => continue,

View File

@ -284,7 +284,7 @@ pub const Parser = struct {
.@"0" => switch (c) { .@"0" => switch (c) {
';' => { ';' => {
self.command = .{ .change_window_title = &.{} }; self.command = .{ .change_window_title = undefined };
self.state = .string; self.state = .string;
self.temp_state = .{ .str = &self.command.change_window_title }; self.temp_state = .{ .str = &self.command.change_window_title };
@ -328,7 +328,7 @@ pub const Parser = struct {
.@"2" => switch (c) { .@"2" => switch (c) {
'2' => self.state = .@"22", '2' => self.state = .@"22",
';' => { ';' => {
self.command = .{ .change_window_title = &.{} }; self.command = .{ .change_window_title = undefined };
self.state = .string; self.state = .string;
self.temp_state = .{ .str = &self.command.change_window_title }; self.temp_state = .{ .str = &self.command.change_window_title };
@ -339,7 +339,7 @@ pub const Parser = struct {
.@"22" => switch (c) { .@"22" => switch (c) {
';' => { ';' => {
self.command = .{ .mouse_shape = .{ .value = &.{} } }; self.command = .{ .mouse_shape = undefined };
self.state = .string; self.state = .string;
self.temp_state = .{ .str = &self.command.mouse_shape.value }; self.temp_state = .{ .str = &self.command.mouse_shape.value };
@ -366,7 +366,7 @@ pub const Parser = struct {
.@"52" => switch (c) { .@"52" => switch (c) {
';' => { ';' => {
self.command = .{ .clipboard_contents = .{ .kind = undefined, .data = &.{} } }; self.command = .{ .clipboard_contents = undefined };
self.state = .clipboard_kind; self.state = .clipboard_kind;
}, },
else => self.state = .invalid, else => self.state = .invalid,

View File

@ -969,44 +969,53 @@ pub fn Stream(comptime Handler: type) type {
.change_window_title => |title| { .change_window_title => |title| {
if (@hasDecl(T, "changeWindowTitle")) { if (@hasDecl(T, "changeWindowTitle")) {
try self.handler.changeWindowTitle(title); try self.handler.changeWindowTitle(title);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.clipboard_contents => |clip| { .clipboard_contents => |clip| {
if (@hasDecl(T, "clipboardContents")) { if (@hasDecl(T, "clipboardContents")) {
try self.handler.clipboardContents(clip.kind, clip.data); try self.handler.clipboardContents(clip.kind, clip.data);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.prompt_start => |v| { .prompt_start => |v| {
if (@hasDecl(T, "promptStart")) switch (v.kind) { if (@hasDecl(T, "promptStart")) {
.primary, .right => try self.handler.promptStart(v.aid, v.redraw), switch (v.kind) {
.continuation => try self.handler.promptContinuation(v.aid), .primary, .right => try self.handler.promptStart(v.aid, v.redraw),
} else log.warn("unimplemented OSC callback: {}", .{cmd}); .continuation => try self.handler.promptContinuation(v.aid),
}
return;
}
}, },
.prompt_end => { .prompt_end => {
if (@hasDecl(T, "promptEnd")) { if (@hasDecl(T, "promptEnd")) {
try self.handler.promptEnd(); try self.handler.promptEnd();
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.end_of_input => { .end_of_input => {
if (@hasDecl(T, "endOfInput")) { if (@hasDecl(T, "endOfInput")) {
try self.handler.endOfInput(); try self.handler.endOfInput();
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.end_of_command => |end| { .end_of_command => |end| {
if (@hasDecl(T, "endOfCommand")) { if (@hasDecl(T, "endOfCommand")) {
try self.handler.endOfCommand(end.exit_code); try self.handler.endOfCommand(end.exit_code);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.report_pwd => |v| { .report_pwd => |v| {
if (@hasDecl(T, "reportPwd")) { if (@hasDecl(T, "reportPwd")) {
try self.handler.reportPwd(v.value); try self.handler.reportPwd(v.value);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.mouse_shape => |v| { .mouse_shape => |v| {
@ -1017,19 +1026,25 @@ pub fn Stream(comptime Handler: type) type {
}; };
try self.handler.setMouseShape(shape); try self.handler.setMouseShape(shape);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
.report_default_color => |v| { .report_default_color => |v| {
if (@hasDecl(T, "reportDefaultColor")) { if (@hasDecl(T, "reportDefaultColor")) {
try self.handler.reportDefaultColor(v.kind, v.terminator); try self.handler.reportDefaultColor(v.kind, v.terminator);
} else log.warn("unimplemented OSC callback: {}", .{cmd}); return;
}
}, },
else => if (@hasDecl(T, "oscUnimplemented")) else => {},
try self.handler.oscUnimplemented(cmd) }
else
log.warn("unimplemented OSC command: {}", .{cmd}), // Fall through for when we don't have a handler.
if (@hasDecl(T, "oscUnimplemented")) {
try self.handler.oscUnimplemented(cmd);
} else {
log.warn("unimplemented OSC command: {s}", .{@tagName(cmd)});
} }
} }
@ -1598,3 +1613,28 @@ test "stream: insert characters" {
for ("\x1B[?42@") |c| try s.next(c); for ("\x1B[?42@") |c| try s.next(c);
try testing.expect(!s.handler.called); try testing.expect(!s.handler.called);
} }
test "stream: too many csi params" {
const H = struct {
pub fn setCursorRight(self: *@This(), v: u16) !void {
_ = v;
_ = self;
unreachable;
}
};
var s: Stream(H) = .{ .handler = .{} };
try s.nextSlice("\x1B[1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1C");
}
test "stream: csi param too long" {
const H = struct {
pub fn setCursorRight(self: *@This(), v: u16) !void {
_ = v;
_ = self;
}
};
var s: Stream(H) = .{ .handler = .{} };
try s.nextSlice("\x1B[1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111C");
}