mirror of
https://github.com/oven-sh/bun
synced 2026-02-17 14:22:01 +00:00
fix(module): prevent crash when resolving bun:main before entry_po… (#27027)
…int.generate() `ServerEntryPoint.source` defaults to `undefined`, and accessing its `.contents` or `.path.text` fields before `generate()` has been called causes a segfault. This happens when `bun:main` is resolved in contexts where `entry_point.generate()` is skipped (HTML entry points) or never called (test runner). Add a `generated` flag to `ServerEntryPoint` and guard both access sites: - `getHardcodedModule()` in ModuleLoader.zig (returns null instead of crashing) - `_resolve()` in VirtualMachine.zig (falls through to normal resolution) ### What does this PR do? ### How did you verify your code works? Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1140,14 +1140,14 @@ export fn Bun__runVirtualModule(globalObject: *JSGlobalObject, specifier_ptr: *c
|
||||
fn getHardcodedModule(jsc_vm: *VirtualMachine, specifier: bun.String, hardcoded: HardcodedModule) ?ResolvedSource {
|
||||
analytics.Features.builtin_modules.insert(hardcoded);
|
||||
return switch (hardcoded) {
|
||||
.@"bun:main" => .{
|
||||
.@"bun:main" => if (jsc_vm.entry_point.generated) .{
|
||||
.allocator = null,
|
||||
.source_code = bun.String.cloneUTF8(jsc_vm.entry_point.source.contents),
|
||||
.specifier = specifier,
|
||||
.source_url = specifier,
|
||||
.tag = .esm,
|
||||
.source_code_needs_deref = true,
|
||||
},
|
||||
} else null,
|
||||
.@"bun:internal-for-testing" => {
|
||||
if (!Environment.isDebug) {
|
||||
if (!is_allowed_to_use_internal_testing_apis)
|
||||
|
||||
Reference in New Issue
Block a user