diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-08 20:51:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-08 21:48:19 -0300 |
| commit | 1f7f9920155b574e0d0e8a94054b596f36e2c065 (patch) | |
| tree | 01e1fe8e637f5e4ed7b010e03d578ac7b71d9a2e /src | |
| parent | e9e074c1e70f7a6c941deca31116882c434fd3b7 (diff) | |
| download | pardes-1f7f9920155b574e0d0e8a94054b596f36e2c065.tar.gz pardes-1f7f9920155b574e0d0e8a94054b596f36e2c065.zip | |
fix: upgrade.load's unlink of an older build's dump file took its path through a catch "" that a path past 4096 bytes would have hit, unlinking nothing: such a path never loads (fs.readFile refuses it, PathTooLong), and the session starts afresh saying so with the dump kept for a Restore, so the unlink 0-terminates the path where it runs and says why it fits; a test loads a record naming a 4096-byte path
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
| -rw-r--r-- | src/upgrade.zig | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/upgrade.zig b/src/upgrade.zig index 5a338ae2..460169e7 100644 --- a/src/upgrade.zig +++ b/src/upgrade.zig @@ -390,8 +390,6 @@ pub fn execAs(gpa: std.mem.Allocator, path: [:0]const u8, rec: *const Record, at pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Options, rec: *Record) !*pardes.Pardes { var kept: [pardes.MAX_PANES]bool = @splat(false); for (rec.ptys[0..rec.nptys]) |p| kept[p.pane] = true; - var path_buf: [4096:0]u8 = undefined; - const path = std.fmt.bufPrintSentinel(&path_buf, "{s}", .{rec.dump}, 0) catch ""; const loaded = loaded: { if (libc.getenv("PARDES_TEST_UPGRADE_REFUSE")) |how| if (rec.refused.len == 0 or std.mem.eql(u8, std.mem.span(how), "all")) break :loaded error.RefusedByTest; @@ -405,7 +403,12 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op if (loaded) |p| { // An older build's dump, a file of its own, goes once loaded; a // label stays among the state file's dumps. - if (rec.label.len == 0) _ = libc.unlink(path); + if (rec.label.len == 0) { + // fs.readFile read it by this path, 0-terminated in 4096 bytes: + // a longer one was refused there (error.PathTooLong), kept. + var path_buf: [4096]u8 = undefined; + _ = libc.unlink(std.fmt.bufPrintSentinel(&path_buf, "{s}", .{rec.dump}, 0) catch unreachable); + } // The binary it replaced, let go: held, its file (deleted) would // keep its blocks for as long as this session runs. if (rec.old >= 0) _ = libc.close(rec.old); @@ -491,3 +494,17 @@ test "an upgrade from the build before reads the dump file its record names, and try std.testing.expectEqualStrings("before the upgrade\n", text); try std.testing.expectError(error.FileNotFound, tmp.dir.statFile(std.testing.io, "pardes-upgrade-1.dump", .{})); } + +test "an older build's dump named by a path past 4096 bytes is refused in words and kept for a Restore" { + const gpa = std.testing.allocator; + var text_buf: [4200]u8 = undefined; + var long: [4096]u8 = undefined; + @memset(&long, 'd'); + long[0] = '/'; + var rec = try Record.decode(try std.fmt.bufPrint(&text_buf, "link -1\nstub -1\nold -1\nwindow 0\nexe /x/pardes\ndump {s}\n", .{&long})); + const q = try load(gpa, gpa, .{ .tty_only = true }, &rec); + defer q.deinit(); + try std.testing.expect(rec.fresh); + const pane = q.panes[q.view().active].?; + try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "Upgrade: no build could load the session") != null); +} |
