diff options
| -rw-r--r-- | core/dump.zig | 23 | ||||
| -rw-r--r-- | core/fuzz.zig | 3 |
2 files changed, 26 insertions, 0 deletions
diff --git a/core/dump.zig b/core/dump.zig index 683f043a..06a3eae5 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -399,6 +399,9 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -475,6 +478,9 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* errdefer { if (notes) |n| n.appendSlice(gpa, l.notes.items) catch {}; l.rollback(); + // Its opens are what the load read: the rollback's, freed (and + // their count may be a damaged one, refused). + p.fs.opens_len = 0; p.fs.deinit(gpa); gpa.destroy(p); } @@ -1417,3 +1423,20 @@ test "optional GPU addon reload generation survives a replica dump" { try std.testing.expectEqual(original.gen, restored.gen); try std.testing.expectEqual(walk.digest(Kind.Slot, &original), walk.digest(Kind.Slot, &restored)); } + +test "a load refused after the core frees what a script's open held once: the rollback's, not the namespace's" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .mounts = &.{.{ .name = "peer", .dial = "/tmp/peer.sock" }} }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + // A script's open of a file of command lines, its last line half + // written: bytes the load makes. + p.fs.opens[0] = .{ .node = 1, .what = .lines }; + try p.fs.opens[0].pending.appendSlice(gpa, "Look half"); + p.fs.opens_len = 1; + const bytes = try byteDump(p); + defer gpa.free(bytes); + // The mounts are read after the core: the same name dialled elsewhere + // refuses the load there. + try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null)); +} diff --git a/core/fuzz.zig b/core/fuzz.zig index c68c7810..dc3e8e07 100644 --- a/core/fuzz.zig +++ b/core/fuzz.zig @@ -790,6 +790,9 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan // Join seed 19224: the theme read after the core a reference to a // slice the core holds, freed by hand and again by the rollback. try loadSeed(bytes, .join, 19224); + // Join seed 31554: the namespace's opens_len past its 64 slots, refused, + // and the rollback's teardown of the namespace read that far. + try loadSeed(bytes, .join, 31554); for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| { try loadSeed(whole, road, 0); for (1..n + 1) |seed| try loadSeed(whole, road, seed); |
