aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-21 17:31:37 +0200
committerHimbeer <himbeer@disroot.org>2024-07-21 17:31:37 +0200
commitd39c98c1678a0b7779ef95e14d4c5a8602110ad2 (patch)
tree7b353a1d9568bb33a26041175812d44f50de30c6 /src
parentabbc6169497c0f8e155d17a497f6ffbfd6d9545c (diff)
resources: Fix zero-length buffer being passed to readHooked
Diffstat (limited to 'src')
-rw-r--r--src/lib/resources.zig41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/lib/resources.zig b/src/lib/resources.zig
index 0c87ede..004b82a 100644
--- a/src/lib/resources.zig
+++ b/src/lib/resources.zig
@@ -101,8 +101,6 @@ const processfs = struct {
var buffer = std.ArrayListAligned(u8, paging.page_size).init(allocator);
defer buffer.clearAndFree();
- try buffer.ensureUnusedCapacity(4096);
-
const ctx = try allocator.create(CreationContext);
defer allocator.destroy(ctx);
@@ -115,10 +113,26 @@ const processfs = struct {
paging.setUserMemoryAccess(false);
defer proc.allowResume();
- while (try rd.readHooked(proc, ctx.buffer.items, .{
+
+ try ctx.buffer.ensureUnusedCapacity(4096);
+
+ var unused_capacity = ctx.buffer.allocatedSlice()[ctx.buffer.items.len..];
+ var n = try rd.readHooked(proc, unused_capacity, .{
.hookFn = loadExe,
.context = ctx,
- }) > 0) {}
+ });
+ while (n > 0) {
+ try buffer.ensureUnusedCapacity(4096);
+
+ unused_capacity = ctx.buffer.allocatedSlice()[ctx.buffer.items.len..];
+ n = try rd.readHooked(proc, unused_capacity, .{
+ .hookFn = loadExe,
+ .context = ctx,
+ });
+
+ ctx.buffer.items.len += n;
+ }
+
const new_proc = try process.create(allocator, ctx.buffer.items);
return new_proc.id;
}
@@ -159,12 +173,27 @@ const processfs = struct {
return;
}
+ ctx.buffer.items.len += n;
+
try ctx.buffer.ensureUnusedCapacity(4096);
- while (try ctx.rd.readHooked(ctx.proc, ctx.buffer.items[ctx.buffer.items.len..], .{
+ var unused_capacity = ctx.buffer.allocatedSlice()[ctx.buffer.items.len..];
+ var n2 = try ctx.rd.readHooked(ctx.proc, unused_capacity, .{
.hookFn = loadExe,
.context = ctx,
- }) > 0) {}
+ });
+ while (n2 > 0) {
+ try ctx.buffer.ensureUnusedCapacity(4096);
+
+ unused_capacity = ctx.buffer.allocatedSlice()[ctx.buffer.items.len..];
+ n2 = try ctx.rd.readHooked(ctx.proc, unused_capacity, .{
+ .hookFn = loadExe,
+ .context = ctx,
+ });
+
+ ctx.buffer.items.len += n2;
+ }
+
const new_proc = try process.create(allocator, ctx.buffer.items);
sysexchange.frameReturn(null, &ctx.proc.trap_frame, new_proc.id);
}