diff options
author | eldritch horrors <pennae@lix.systems> | 2024-03-04 06:18:20 +0100 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-03-04 07:11:25 +0100 |
commit | 001be527944665433a149add979b9a8139787ee6 (patch) | |
tree | a0375d20f37c1ac87e2ccd3ba4132c497d6d9057 /src/libexpr/eval.cc | |
parent | a089d8f5f6f96ea3f35790c36b6456e71f477879 (diff) |
Merge pull request #9430 from hercules-ci/remove-vlas
Fix stack overflow in `filter`
(cherry picked from commit cb7f25869daa2491eeac5fee49ad8f31b2218c15)
Change-Id: Ib90f97a9805bbb4d0e2741551d490f054fc0a675
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index f5eacd0e0..d414db79b 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -13,6 +13,7 @@ #include "function-trace.hh" #include "profiles.hh" #include "print.hh" +#include "gc-small-vector.hh" #include <algorithm> #include <chrono> @@ -28,6 +29,7 @@ #include <sys/resource.h> #include <nlohmann/json.hpp> +#include <boost/container/small_vector.hpp> #if HAVE_BOEHMGC @@ -1701,7 +1703,7 @@ void EvalState::callFunction(Value & fun, size_t nrArgs, Value * * args, Value & /* We have all the arguments, so call the primop with the previous and new arguments. */ - Value * vArgs[arity]; + Value * vArgs[maxPrimOpArity]; auto n = argsDone; for (Value * arg = &vCur; arg->isPrimOpApp(); arg = arg->primOpApp.left) vArgs[--n] = arg->primOpApp.right; @@ -1764,11 +1766,11 @@ void ExprCall::eval(EvalState & state, Env & env, Value & v) // 4: about 60 // 5: under 10 // This excluded attrset lambdas (`{...}:`). Contributions of mixed lambdas appears insignificant at ~150 total. - Value * vArgs[args.size()]; + SmallValueVector<4> vArgs(args.size()); for (size_t i = 0; i < args.size(); ++i) vArgs[i] = args[i]->maybeThunk(state, env); - state.callFunction(vFun, args.size(), vArgs, v, pos); + state.callFunction(vFun, args.size(), vArgs.data(), v, pos); } @@ -2007,8 +2009,9 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v) return result; }; - Value values[es->size()]; - Value * vTmpP = values; + // List of returned strings. References to these Values must NOT be persisted. + SmallTemporaryValueVector<conservativeStackReservation> values(es->size()); + Value * vTmpP = values.data(); for (auto & [i_pos, i] : *es) { Value & vTmp = *vTmpP++; |