mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/sentry: uuid string is null-terminated
This commit is contained in:
@ -14,8 +14,8 @@ pub const UUID = struct {
|
|||||||
return c.sentry_uuid_is_nil(&self.value) != 0;
|
return c.sentry_uuid_is_nil(&self.value) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn string(self: UUID) [37]u8 {
|
pub fn string(self: UUID) [36:0]u8 {
|
||||||
var buf: [37]u8 = undefined;
|
var buf: [36:0]u8 = undefined;
|
||||||
c.sentry_uuid_as_string(&self.value, &buf);
|
c.sentry_uuid_as_string(&self.value, &buf);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,21 @@ pub const Transport = struct {
|
|||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
const alloc = arena.allocator();
|
const alloc = arena.allocator();
|
||||||
|
|
||||||
// Some envelopes don't contain a crash report. Discord them.
|
// Parse into an envelope structure
|
||||||
if (try shouldDiscard(alloc, envelope)) {
|
const json = envelope.serialize();
|
||||||
|
defer sentry.free(@ptrCast(json.ptr));
|
||||||
|
var parsed: crash.Envelope = parsed: {
|
||||||
|
var fbs = std.io.fixedBufferStream(json);
|
||||||
|
break :parsed try crash.Envelope.parse(alloc, fbs.reader());
|
||||||
|
};
|
||||||
|
defer parsed.deinit();
|
||||||
|
|
||||||
|
// If our envelope doesn't have an event then we don't do anything.
|
||||||
|
// To figure this out we first encode it into a string, parse it,
|
||||||
|
// and check if it has an event. Kind of wasteful but the best
|
||||||
|
// option we have at the time of writing this since the C API doesn't
|
||||||
|
// expose this information.
|
||||||
|
if (try shouldDiscard(&parsed)) {
|
||||||
log.info("sentry envelope does not contain crash, discarding", .{});
|
log.info("sentry envelope does not contain crash, discarding", .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -116,28 +129,16 @@ pub const Transport = struct {
|
|||||||
crash_dir,
|
crash_dir,
|
||||||
try std.fmt.allocPrint(alloc, "{s}.ghosttycrash", .{uuid.string()}),
|
try std.fmt.allocPrint(alloc, "{s}.ghosttycrash", .{uuid.string()}),
|
||||||
});
|
});
|
||||||
log.debug("writing crash report to disk path={s}", .{path});
|
const file = try std.fs.cwd().createFile(path, .{});
|
||||||
try envelope.writeToFile(path);
|
defer file.close();
|
||||||
|
try file.writer().writeAll(json);
|
||||||
|
|
||||||
log.warn("crash report written to disk path={s}", .{path});
|
log.warn("crash report written to disk path={s}", .{path});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shouldDiscard(alloc: Allocator, envelope: *sentry.Envelope) !bool {
|
fn shouldDiscard(envelope: *const crash.Envelope) !bool {
|
||||||
// If our envelope doesn't have an event then we don't do anything.
|
|
||||||
// To figure this out we first encode it into a string, parse it,
|
|
||||||
// and check if it has an event. Kind of wasteful but the best
|
|
||||||
// option we have at the time of writing this since the C API doesn't
|
|
||||||
// expose this information.
|
|
||||||
const json = envelope.serialize();
|
|
||||||
defer sentry.free(@ptrCast(json.ptr));
|
|
||||||
|
|
||||||
// Parse into an envelope structure
|
|
||||||
var fbs = std.io.fixedBufferStream(json);
|
|
||||||
var parsed = try crash.Envelope.parse(alloc, fbs.reader());
|
|
||||||
defer parsed.deinit();
|
|
||||||
|
|
||||||
// If we have an event item then we're good.
|
// If we have an event item then we're good.
|
||||||
for (parsed.items) |item| {
|
for (envelope.items) |item| {
|
||||||
if (item.type == .event) return false;
|
if (item.type == .event) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user