diff options
author | 2023-02-24 02:37:08 +0200 | |
---|---|---|
committer | 2023-02-23 16:37:08 -0800 | |
commit | 5929daeeae1f528abab31979a0a28bc87a03b1f4 (patch) | |
tree | 278dfa07811bb60b72497f059c33245a339707b4 /src | |
parent | 4122cb0b198bad22c8bc033c8ced58716f0309ad (diff) | |
download | bun-5929daeeae1f528abab31979a0a28bc87a03b1f4.tar.gz bun-5929daeeae1f528abab31979a0a28bc87a03b1f4.tar.zst bun-5929daeeae1f528abab31979a0a28bc87a03b1f4.zip |
fix illegal memory reference in `bun link` (#2147)
Diffstat (limited to '')
-rw-r--r-- | src/install/resolvers/folder_resolver.zig | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/install/resolvers/folder_resolver.zig b/src/install/resolvers/folder_resolver.zig index 968ee57ca..c16f0c8ed 100644 --- a/src/install/resolvers/folder_resolver.zig +++ b/src/install/resolvers/folder_resolver.zig @@ -33,7 +33,7 @@ pub const FolderResolution = union(Tag) { return std.hash.Wyhash.hash(0, normalized_path); } - pub fn NewResolver(comptime tag: Resolution.Tag) type { + fn NewResolver(comptime tag: Resolution.Tag) type { return struct { folder_path: string, @@ -50,11 +50,10 @@ pub const FolderResolution = union(Tag) { }; } - pub const Resolver = NewResolver(Resolution.Tag.folder); - pub const SymlinkResolver = NewResolver(Resolution.Tag.symlink); - pub const WorkspaceResolver = NewResolver(Resolution.Tag.workspace); - pub const CacheFolderResolver = struct { - folder_path: []const u8 = "", + const Resolver = NewResolver(Resolution.Tag.folder); + const SymlinkResolver = NewResolver(Resolution.Tag.symlink); + const WorkspaceResolver = NewResolver(Resolution.Tag.workspace); + const CacheFolderResolver = struct { version: Semver.Version, pub fn resolve(this: @This(), comptime Builder: type, _: Builder, _: JSAst.Expr) !Resolution { @@ -182,14 +181,18 @@ pub const FolderResolution = union(Tag) { if (entry.found_existing) return entry.value_ptr.*; const package: Lockfile.Package = switch (global_or_relative) { - .global => readPackageJSONFromDisk( - manager, - abs, - version, - Features.link, - SymlinkResolver, - SymlinkResolver{ .folder_path = non_normalized_path }, - ), + .global => brk: { + var path: [bun.MAX_PATH_BYTES]u8 = undefined; + std.mem.copy(u8, &path, non_normalized_path); + break :brk readPackageJSONFromDisk( + manager, + abs, + version, + Features.link, + SymlinkResolver, + SymlinkResolver{ .folder_path = path[0..non_normalized_path.len] }, + ); + }, .relative => |tag| switch (tag) { .folder => readPackageJSONFromDisk( manager, |