feat(stageb): add shallow recursion guards to StageB driver/body extractor
This commit is contained in:
@ -48,6 +48,19 @@ static box StageBArgsBox {
|
||||
// Phase 25.1c: Body extraction + bundle + using + trim
|
||||
static box StageBBodyExtractorBox {
|
||||
build_body_src(src, args) {
|
||||
// ============================================================================
|
||||
// Depth guard: prevent accidental recursion inside Stage‑B body extractor
|
||||
// ============================================================================
|
||||
{
|
||||
local depth = env.get("HAKO_STAGEB_BODY_DEPTH")
|
||||
if depth != null && ("" + depth) != "0" {
|
||||
print("[stageb/recursion] StageBBodyExtractorBox.build_body_src recursion detected")
|
||||
// Fail-fast but still return a sensible value: fall back to original src
|
||||
return src
|
||||
}
|
||||
env.set("HAKO_STAGEB_BODY_DEPTH", "1")
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// 4) Body extraction: extract main method body from box Main wrapper
|
||||
// ============================================================================
|
||||
@ -594,6 +607,8 @@ static box StageBBodyExtractorBox {
|
||||
if e > b { body_src = s.substring(b, e) } else { body_src = "" }
|
||||
}
|
||||
|
||||
// Clear depth guard before returning
|
||||
env.set("HAKO_STAGEB_BODY_DEPTH", "0")
|
||||
return body_src
|
||||
}
|
||||
}
|
||||
@ -601,6 +616,18 @@ static box StageBBodyExtractorBox {
|
||||
// Phase 25.1c: Main driver logic
|
||||
static box StageBDriverBox {
|
||||
main(args) {
|
||||
// ============================================================================
|
||||
// Depth guard: prevent accidental recursion in Stage‑B driver entry
|
||||
// ============================================================================
|
||||
{
|
||||
local depth = env.get("HAKO_STAGEB_DRIVER_DEPTH")
|
||||
if depth != null && ("" + depth) != "0" {
|
||||
print("[stageb/recursion] StageBDriverBox.main recursion detected")
|
||||
return -1
|
||||
}
|
||||
env.set("HAKO_STAGEB_DRIVER_DEPTH", "1")
|
||||
}
|
||||
|
||||
local src = StageBArgsBox.resolve_src(args)
|
||||
|
||||
// 2) Stage‑3 acceptance default ON for selfhost (env may turn off; keep tolerant here)
|
||||
@ -685,6 +712,8 @@ static box StageBDriverBox {
|
||||
}
|
||||
|
||||
print(ast_json)
|
||||
// Clear depth guard before returning
|
||||
env.set("HAKO_STAGEB_DRIVER_DEPTH", "0")
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user