lix/src/libstore/build
jade c897fba787 store: fix null reference from DerivationGoal::waiteeDone
This happened during a PathSubstitutionGoal of a .drv file:

substitution of '/tmp/jade/nix-test/ca/eval-store/store/1lj7lsq5y0f25mfbnq6d3zd0bw5ay33n-dependencies-input-2.drv'

What happened here is that since PathSubstitutionGoal is not a
DerivationGoal, in production builds, the UB was not caught, since it
would early-exit from failing a dynamic_cast to DerivationGoal * on the
very next line, but before the null reference was ever used.

This was nonetheless UB. The fix should be to just rearrange the two
lines; I don't think there is a further bug there, since *substituting a
.drv* **necessarily** means you cannot have the representation of
the derivation as would be necessary for drv to not be null there.

Test failure:

++(eval-store.sh:12) _RR_TRACE_DIR=/home/jade/.local/share/rr rr record -- nix build -f dependencies.nix --eval-store /tmp/jade/nix-test/ca/eval-store/eval-store -o /tmp/jade/nix-test/ca/eval-store/result
don't know how to build these paths:
  /tmp/jade/nix-test/ca/eval-store/store/6y51mf0p57ggipgab6hdjabbvplzsicq-dependencies-top.drv
copying 1 paths...
copying path '/tmp/jade/nix-test/ca/eval-store/store/8027afyvqb87y1sf5xhdkqsflqn1ziy8-dependencies.builder0.sh' to 'local'...
copying 1 paths...
copying path '/tmp/jade/nix-test/ca/eval-store/store/7r5pqyncvfgrryf9gzy1z56z3xigi61x-builder-dependencies-input-0.sh' to 'local'...
copying 1 paths...
copying path '/tmp/jade/nix-test/ca/eval-store/store/nhmgm87zlqy3ks96dxrn7l37b72azi99-builder-dependencies-input-1.sh' to 'local'...
copying 1 paths...
copying path '/tmp/jade/nix-test/ca/eval-store/store/nq4qa2j6y8ajqazlfq6h46ck637my1n6-builder-dependencies-input-2.sh' to 'local'...
copying 1 paths...
copying path '/tmp/jade/nix-test/ca/eval-store/store/6vh0vna9l5afck01y7iaks3hm9ikwqyj-builder-fod-input.sh' to 'local'...
building '/tmp/jade/nix-test/ca/eval-store/store/gy91pqymf2nc5v7ld1bad94xpwxdi25s-dependencies-input-0.drv'...
building '/tmp/jade/nix-test/ca/eval-store/store/w7wlkjx97ivmnrymkac5av3nyp94hzvq-dependencies-input-1.drv'...
../src/libstore/build/derivation-goal.cc:1556:22: runtime error: reference binding to null pointer of type 'Derivation'
    0 0x734ba59a6886 in nix::DerivationGoal::waiteeDone(std::shared_ptr<nix::Goal>, nix::Goal::ExitCode) /home/jade/lix/lix2/build/src/libstore/build/derivation-goal.cc:1556:12
    1 0x734ba59c0962 in nix::Goal::amDone(nix::Goal::ExitCode, std::optional<nix::Error>) /home/jade/lix/lix2/build/src/libstore/build/goal.cc:95:25
    2 0x734ba5a1c44a in nix::PathSubstitutionGoal::done(nix::Goal::ExitCode, nix::BuildResult::Status, std::optional<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>) /home/jade/lix/lix2/build/src/libstore/build/substitution-goal.cc:38:5
    3 0x734ba5a1b454 in nix::PathSubstitutionGoal::init() /home/jade/lix/lix2/build/src/libstore/build/substitution-goal.cc:56:9
    4 0x734ba5a2a6c6 in nix::Worker::run(std::set<std::shared_ptr<nix::Goal>, nix::CompareGoalPtrs, std::allocator<std::shared_ptr<nix::Goal>>> const&) /home/jade/lix/lix2/build/src/libstore/build/worker.cc:320:23
    5 0x734ba59b93d8 in nix::Store::buildPathsWithResults(std::vector<nix::DerivedPath, std::allocator<nix::DerivedPath>> const&, nix::BuildMode, std::shared_ptr<nix::Store>) /home/jade/lix/lix2/build/src/libstore/build/entry-points.cc:60:12
    6 0x734ba663c107 in nix::Installable::build2(nix::ref<nix::Store>, nix::ref<nix::Store>, nix::Realise, std::vector<nix::ref<nix::Installable>, std::allocator<nix::ref<nix::Installable>>> const&, nix::BuildMode) /home/jade/lix/lix2/build/src/libcmd/installables.cc:637:36

Change-Id: Id0e651e480bebf6356733b01bc639e9bb59c7bd0
2024-06-18 19:26:54 -07:00
..
child.cc util.{hh,cc}: Split out child.{hh,cc} 2024-05-29 11:01:34 +02:00
child.hh util.{hh,cc}: Split out child.{hh,cc} 2024-05-29 11:01:34 +02:00
derivation-goal.cc store: fix null reference from DerivationGoal::waiteeDone 2024-06-18 19:26:54 -07:00
derivation-goal.hh Make things that can throw not noexcept anymore 2024-03-29 20:26:38 -07:00
drv-output-substitution-goal.cc libutil: remove callback.hh 2024-05-10 02:21:11 +02:00
drv-output-substitution-goal.hh libstore: de-callback-ify CA realisation substitution 2024-05-09 23:18:05 +02:00
entry-points.cc libexpr: Support structured error classes 2024-03-09 04:47:05 -07:00
goal.cc Adapt scheduler to work with dynamic derivations 2023-08-25 10:01:25 -04:00
goal.hh Make things that can throw not noexcept anymore 2024-03-29 20:26:38 -07:00
hook-instance.cc util.{hh,cc}: Split out child.{hh,cc} 2024-05-29 11:01:34 +02:00
hook-instance.hh util.{hh,cc}: Split out processes.{hh,cc} 2024-05-29 11:01:34 +02:00
local-derivation-goal.cc libstore/build: copy ca-certificates too 2024-05-31 07:54:18 +00:00
local-derivation-goal.hh util.{hh,cc}: Split out processes.{hh,cc} 2024-05-29 11:01:34 +02:00
personality.cc Also set the PER_LINUX32 personality flag on armv5tel-linux 2023-06-02 03:04:13 -06:00
personality.hh Add pre-commit checks 2024-03-29 22:57:40 -07:00
sandbox-defaults.sb Merge pull request #9641 from amarshall/darwin-sandbox-stderr 2024-03-04 07:26:03 +01:00
sandbox-minimal.sb Move macOS sandbox files to sr/libstore/build 2023-01-04 04:50:45 -08:00
sandbox-network.sb Move macOS sandbox files to sr/libstore/build 2023-01-04 04:50:45 -08:00
substitution-goal.cc util.hh: split out signals stuff 2024-03-11 00:52:09 -07:00
substitution-goal.hh Adapt scheduler to work with dynamic derivations 2023-08-25 10:01:25 -04:00
worker.cc worker: process timeouts first, and exclusively 2024-05-26 20:57:09 +00:00
worker.hh libstore: limit CA realisation info substitution concurrency 2024-05-07 14:35:20 +00:00