Skip to content

Commit 81d84cf

Browse files
committed
fix: ownership guard — never fixup payloads inherited from another home
gcc_post_install_fixup now skips payloads whose canonical path resolves outside this MCPP_HOME's registry: inherited (symlinked) payloads belong to their owner home, whose fixup is already valid; patching through the symlink rewrote the canonical binaries against ephemeral paths and bricked the owner's toolchain. Verified: fresh-home e2e (26/28/29/31) pass and the owner toolchain stays intact.
1 parent db3b47e commit 81d84cf

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/cli.cppm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,22 @@ void fixup_clang_cfg(const std::filesystem::path& payloadRoot,
10251025
// fresh-sandbox glibc gcc unable to find the C library: stdlib.h not found).
10261026
void gcc_post_install_fixup(const mcpp::config::GlobalConfig& cfg,
10271027
const std::filesystem::path& payloadRoot) {
1028+
// Ownership guard: payloads inherited via symlink from another MCPP_HOME
1029+
// are not ours to patch — their owner already ran the fixup, and patching
1030+
// through the symlink would rewrite the canonical files against OUR
1031+
// (possibly ephemeral) paths, bricking the owner's toolchain.
1032+
{
1033+
std::error_code ec;
1034+
auto canonicalRoot = std::filesystem::weakly_canonical(payloadRoot, ec);
1035+
auto homeRegistry = std::filesystem::weakly_canonical(cfg.registryDir, ec);
1036+
if (!ec && !canonicalRoot.string().starts_with(homeRegistry.string())) {
1037+
mcpp::log::verbose("toolchain", std::format(
1038+
"skip gcc fixup: payload '{}' resolves outside this home ('{}') — "
1039+
"inherited payload, owner is responsible for its fixup",
1040+
payloadRoot.string(), canonicalRoot.string()));
1041+
return;
1042+
}
1043+
}
10281044
auto xlEnv = mcpp::config::make_xlings_env(cfg);
10291045
auto glibcRoot = mcpp::xlings::paths::xim_tool_root(xlEnv, "glibc");
10301046
std::filesystem::path glibcLibDir;

0 commit comments

Comments
 (0)