Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
9f5bc62b72 Fix use-after-free bug in JSON parsing error messages
When workspace package.json parsing fails, error messages contained references
to freed memory for both line text and file paths, causing corrupted output.

This patch fixes two separate use-after-free issues:

1. Line text corruption: Enable clone_line_text=true for CLI logger so line text
   gets cloned before source buffers are freed
2. Path corruption: Extend cloneLineText() to also clone file paths when
   line text cloning is enabled

The fix ensures error messages display correctly instead of showing corrupted
characters like "�������������������" and garbled paths.

Fixes workspace JSON parsing error display corruption.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 23:37:44 +00:00
3 changed files with 12 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ pub const Cli = struct {
is_main_thread = true;
start_time = std.time.nanoTimestamp();
log_ = logger.Log.init(allocator);
log_.clone_line_text = true;
var log = &log_;

View File

@@ -721,6 +721,7 @@ pub fn init(
else => break,
};
var log = logger.Log.init(ctx.allocator);
log.clone_line_text = true;
defer log.deinit();
_ = workspace_names.processNamesArray(
ctx.allocator,

View File

@@ -216,12 +216,19 @@ pub const Data = struct {
}
pub fn cloneLineText(this: Data, should: bool, allocator: std.mem.Allocator) OOM!Data {
if (!should or this.location == null or this.location.?.line_text == null)
if (!should or this.location == null)
return this;
const new_line_text = try allocator.dupe(u8, this.location.?.line_text.?);
var new_location = this.location.?;
new_location.line_text = new_line_text;
// Clone line_text if it exists
if (this.location.?.line_text != null) {
new_location.line_text = try allocator.dupe(u8, this.location.?.line_text.?);
}
// Also clone the file path to prevent use-after-free issues
new_location.file = try allocator.dupe(u8, this.location.?.file);
return Data{
.text = this.text,
.location = new_location,