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/primops.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/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ac8dbeaf1..b906e7747 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -4,6 +4,7 @@ #include "eval-inline.hh" #include "eval.hh" #include "eval-settings.hh" +#include "gc-small-vector.hh" #include "globals.hh" #include "json-to-value.hh" #include "names.hh" @@ -2726,7 +2727,7 @@ static void prim_catAttrs(EvalState & state, const PosIdx pos, Value * * args, V auto attrName = state.symbols.create(state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.catAttrs")); state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.catAttrs"); - Value * res[args[1]->listSize()]; + SmallValueVector<nonRecursiveStackReservation> res(args[1]->listSize()); size_t found = 0; for (auto v2 : args[1]->listItems()) { @@ -3061,8 +3062,7 @@ static void prim_filter(EvalState & state, const PosIdx pos, Value * * args, Val state.forceFunction(*args[0], pos, "while evaluating the first argument passed to builtins.filter"); - // FIXME: putting this on the stack is risky. - Value * vs[args[1]->listSize()]; + SmallValueVector<nonRecursiveStackReservation> vs(args[1]->listSize()); size_t k = 0; bool same = true; @@ -3451,7 +3451,8 @@ static void prim_concatMap(EvalState & state, const PosIdx pos, Value * * args, state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.concatMap"); auto nrLists = args[1]->listSize(); - Value lists[nrLists]; + // List of returned lists before concatenation. References to these Values must NOT be persisted. + SmallTemporaryValueVector<conservativeStackReservation> lists(nrLists); size_t len = 0; for (unsigned int n = 0; n < nrLists; ++n) { |