1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

libstore: Fix dangling pointers in DerivationGoal constructors

This leads to a use-after free, because staticOutputHashes returns a temporary
object that dies before we can do a `return *mOutputHash`.

This is most likely the cause for random failures in Hydra [1].

[1]: https://hydra.nixos.org/build/305091330/nixlog/2
This commit is contained in:
Sergei Zimmerman 2025-08-15 16:39:28 +03:00
parent 4e776a5be8
commit cea85e79ee
No known key found for this signature in database

View file

@ -34,11 +34,10 @@ DerivationGoal::DerivationGoal(
, drvPath(drvPath)
, wantedOutput(wantedOutput)
, outputHash{[&] {
if (auto * mOutputHash = get(staticOutputHashes(worker.evalStore, drv), wantedOutput))
auto outputHashes = staticOutputHashes(worker.evalStore, drv);
if (auto * mOutputHash = get(outputHashes, wantedOutput))
return *mOutputHash;
else
throw Error(
"derivation '%s' does not have output '%s'", worker.store.printStorePath(drvPath), wantedOutput);
throw Error("derivation '%s' does not have output '%s'", worker.store.printStorePath(drvPath), wantedOutput);
}()}
, buildMode(buildMode)
{