From 8bd60936b51c9944ae8dedf4ea840abb1cc3994c Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Fri, 1 May 2020 12:17:00 +0200 Subject: [PATCH] Fix some null pointer access crashes Fixes https://github.com/sass/libsass/issues/3063 Fixes https://github.com/sass/libsass/issues/3035 --- src/cssize.cpp | 5 +++-- src/extender.cpp | 1 + src/memory/memory_pool.hpp | 2 ++ src/output.cpp | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cssize.cpp b/src/cssize.cpp index 88c0ab2b04..a651186eec 100644 --- a/src/cssize.cpp +++ b/src/cssize.cpp @@ -380,7 +380,7 @@ namespace Sass { bool Cssize::bubblable(Statement* s) { - return Cast(s) || s->bubbles(); + return Cast(s) || (s && s->bubbles()); } Block* Cssize::flatten(const Block* b) @@ -479,7 +479,8 @@ namespace Sass { children->pstate(), children->length(), children->is_root()); - bb->append(ss->perform(this)); + auto evaled = ss->perform(this); + if (evaled) bb->append(evaled); Block_Obj wrapper_block = SASS_MEMORY_NEW(Block, children->pstate(), diff --git a/src/extender.cpp b/src/extender.cpp index 937ea5bb00..8b0fd1273e 100644 --- a/src/extender.cpp +++ b/src/extender.cpp @@ -147,6 +147,7 @@ namespace Sass { for (auto target : extensions) { SimpleSelector* key = target.first; ExtSelExtMapEntry& val = target.second; + if (val.empty()) continue; if (originals.find(key) == originals.end()) { const Extension& extension = val.front().second; if (extension.isOptional) continue; diff --git a/src/memory/memory_pool.hpp b/src/memory/memory_pool.hpp index e29a054b2a..d2cef9930d 100644 --- a/src/memory/memory_pool.hpp +++ b/src/memory/memory_pool.hpp @@ -55,7 +55,9 @@ namespace Sass { std::vector arenas; // One pointer for every bucket (zero init) + #ifdef _MSC_VER #pragma warning (suppress:4351) + #endif void* freeList[SassAllocatorBuckets]{}; // Increase the address until it sits on a diff --git a/src/output.cpp b/src/output.cpp index 04819bad4d..0748cd4643 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -289,7 +289,7 @@ namespace Sass { for (size_t i = 0, L = b->length(); i < L; ++i) { Statement_Obj stm = b->get(i); - stm->perform(this); + if (stm) stm->perform(this); if (i < L - 1 && format) append_special_linefeed(); }