From e34833c0253340f47dc0add8609eb86cf9cba19b Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Sun, 4 Aug 2024 20:19:58 -0700 Subject: tree-wide: fix a pile of lints This: - Converts a bunch of C style casts into C++ casts. - Removes some very silly pointer subtraction code (which is no more or less busted on i686 than it began) - Fixes some "technically UB" that never had to be UB in the first place. - Makes finally follow the noexcept status of the inner function. Maybe in the future we should ban the function from not being noexcept, but that is not today. - Makes various locally-used exceptions inherit from std::exception. Change-Id: I22e66972602604989b5e494fd940b93e0e6e9297 --- src/libstore/daemon.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libstore/daemon.cc') diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index aada43253..5ac9cd2ef 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -453,7 +453,11 @@ static void performOp(TunnelLogger * logger, ref store, hashAlgo = parseHashType(hashAlgoRaw); } - GeneratorSource dumpSource{[&]() -> WireFormatGenerator { + // Note to future maintainers: do *not* inline this into the + // generator statement as the lambda itself needs to live to the + // end of the generator's lifetime and is otherwise a UAF. + // NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines): does not outlive the outer function + auto g = [&]() -> WireFormatGenerator { if (method == FileIngestionMethod::Recursive) { /* We parse the NAR dump through into `saved` unmodified, so why all this extra work? We still parse the NAR so @@ -489,7 +493,8 @@ static void performOp(TunnelLogger * logger, ref store, } co_yield std::move(file->contents); } - }()}; + }; + GeneratorSource dumpSource{g()}; logger->startWork(); auto path = store->addToStoreFromDump(dumpSource, baseName, method, hashAlgo); logger->stopWork(); -- cgit v1.2.3