From 0537dd2c55fef7ed954fd991ad526bbcbc4be8d0 Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Wed, 23 Oct 2019 19:55:20 +0200 Subject: [PATCH] Fix possible memory leak in permutation function Fixes https://github.com/sass/libsass/issues/3014 --- src/permutate.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/permutate.hpp b/src/permutate.hpp index 2b83d02f5..01077940c 100644 --- a/src/permutate.hpp +++ b/src/permutate.hpp @@ -22,14 +22,18 @@ namespace Sass { const std::vector>& in) { - size_t L = in.size(); - size_t n = 0; + size_t L = in.size(), n = 0; + + // Exit early if any entry is empty + for (size_t i = 0; i < L; i += 1) { + if (in[i].size() == 0) return {}; + } + size_t* state = new size_t[L + 1]; std::vector> out; // First initialize all states for every permutation group for (size_t i = 0; i < L; i += 1) { - if (in[i].size() == 0) return {}; state[i] = in[i].size() - 1; } while (true) {