fuzz: src/terminal/stream.zig

osc.zig: undefined pointer was dereferenced when warning was issued
for handler missing
Parser.zig: too many parameters was not handled in the final case
Parser.zig: parameters being too long (>255 digits) was not handled
This commit is contained in:
Nameless
2023-10-19 14:28:23 -05:00
parent ee0b79fa07
commit 81f7ae63b0
2 changed files with 10 additions and 4 deletions

View File

@ -373,6 +373,9 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
break :param null; break :param null;
} }
// Ignore parameters that are too long
if (self.param_acc_idx == std.math.maxInt(u8)) break :param null;
// A numeric value. Add it to our accumulator. // A numeric value. Add it to our accumulator.
if (self.param_acc_idx > 0) { if (self.param_acc_idx > 0) {
self.param_acc *|= 10; self.param_acc *|= 10;
@ -388,6 +391,9 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
break :osc_put null; break :osc_put null;
}, },
.csi_dispatch => csi_dispatch: { .csi_dispatch => csi_dispatch: {
// Ignore too many parameters
if (self.params_idx >= MAX_PARAMS) break :csi_dispatch null;
// Finalize parameters if we have one // Finalize parameters if we have one
if (self.param_acc_idx > 0) { if (self.param_acc_idx > 0) {
self.params[self.params_idx] = self.param_acc; self.params[self.params_idx] = self.param_acc;

View File

@ -284,7 +284,7 @@ pub const Parser = struct {
.@"0" => switch (c) { .@"0" => switch (c) {
';' => { ';' => {
self.command = .{ .change_window_title = undefined }; self.command = .{ .change_window_title = &.{} };
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 = undefined }; self.command = .{ .change_window_title = &.{} };
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 = undefined }; self.command = .{ .mouse_shape = .{ .value = &.{} } };
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 = undefined }; self.command = .{ .clipboard_contents = .{ .kind = undefined, .data = &.{} } };
self.state = .clipboard_kind; self.state = .clipboard_kind;
}, },
else => self.state = .invalid, else => self.state = .invalid,