Skip to content

Commit 47c4db6

Browse files
authored
fix: dangling stack pointer segfault in upgrade for revisioned packages (#104)
When a formula has revision > 0, prepareOne() formatted the version string into a stack-local buffer. That pointer was returned in PrepareResult.success.version, but the stack frame was destroyed when prepareOne returned — leaving the swap phase reading dead memory. Allocate from the arena instead, which outlives the swap phase.
1 parent 8f6d481 commit 47c4db6

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

src/cmd/upgrade.zig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ fn prepareOne(arena: Allocator, ctx: PrepareContext, item: OutdatedFormula) Prep
6868
}
6969

7070
const version_base = ctx.index.getString(entry.version_offset);
71-
var pkg_ver_buf_main: [256]u8 = undefined;
7271
const version = if (entry.revision > 0)
73-
std.fmt.bufPrint(&pkg_ver_buf_main, "{s}_{d}", .{ version_base, entry.revision }) catch version_base
72+
std.fmt.allocPrint(arena, "{s}_{d}", .{ version_base, entry.revision }) catch version_base
7473
else
7574
version_base;
7675

0 commit comments

Comments
 (0)