Skip to content

Commit

Permalink
fix double free in kitty desktop notification parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollie committed Sep 12, 2024
1 parent 74e3eee commit 2048f46
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/terminal/kitty/desktop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ payload: ?[]const u8 = null,
terminator: Terminator = .st,

/// we use an arena to make cleaning up allocations simpler
arena: std.heap.ArenaAllocator,
arena: ?std.heap.ArenaAllocator = null,

/// these are used internally by the parser to keep track of
/// locations in the buffer, they should be ignored outside of
Expand Down Expand Up @@ -259,7 +259,8 @@ pub fn init(gpa_alloc: std.mem.Allocator, option_start: usize) KittyDesktopNotif
}

pub fn deinit(self: *KittyDesktopNotification) void {
self.arena.deinit();
if (self.arena) |arena| arena.deinit();
self.arena = null;
}

pub fn startOption(self: *KittyDesktopNotification, option_start: usize) void {
Expand Down Expand Up @@ -324,7 +325,11 @@ pub fn endOption(self: *KittyDesktopNotification, parser: *Parser, option_end: u
self._internal.key_end = null;
self._internal.value_start = null;

const alloc = self.arena.allocator();
const alloc = (self.arena orelse {
log.warn("no arena?", .{});
parser.state = .invalid;
return;
}).allocator();

switch (key) {
// action
Expand Down Expand Up @@ -539,7 +544,11 @@ pub fn end(self: *KittyDesktopNotification, parser: *Parser, option_end: usize)
return;
}

const alloc = self.arena.allocator();
const alloc = (self.arena orelse {
log.warn("no arena?", .{});
parser.state = .invalid;
return;
}).allocator();

if (self.metadata.e) {
const size = simd.base64.maxLen(value);
Expand Down

0 comments on commit 2048f46

Please sign in to comment.