diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-02-05 12:54:38 +0100 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-02-06 08:07:09 +0100 |
commit | f289fe3dca487c45417f7b40d51a4830f3369fb1 (patch) | |
tree | 0380154bd3d97fc79d390baaaf305c1b362396e7 /include | |
parent | 6b6849107562b258aa8858e94ff3c07160f07062 (diff) |
Prevent JS from creating css::uno::Sequence of negative size
Change-Id: I2449723162744e9ce3cb3e3172ce8acae0adf4db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162998
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/static/unoembindhelpers/PrimaryBindings.hxx | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/include/static/unoembindhelpers/PrimaryBindings.hxx b/include/static/unoembindhelpers/PrimaryBindings.hxx index 6f8005b1656c..61efaf01153b 100644 --- a/include/static/unoembindhelpers/PrimaryBindings.hxx +++ b/include/static/unoembindhelpers/PrimaryBindings.hxx @@ -52,6 +52,14 @@ template <typename T> struct UnoInOutParam T value; }; +inline void checkSequenceSize(sal_Int32 size) +{ + if (size < 0) + { + throw std::invalid_argument("negative size"); + } +} + template <typename T> void checkSequenceAccess(css::uno::Sequence<T> const& sequence, sal_Int32 index) { @@ -64,13 +72,13 @@ void checkSequenceAccess(css::uno::Sequence<T> const& sequence, sal_Int32 index) template <typename T> void registerSequence(char const* name) { emscripten::class_<css::uno::Sequence<T>>(name) - .template constructor<sal_Int32>() + .constructor(+[](sal_Int32 size) { + checkSequenceSize(size); + return css::uno::Sequence<T>(size); + }) .function("resize", +[](css::uno::Sequence<T>& self, sal_Int32 size) { - if (size < 0) - { - throw std::invalid_argument("negative size"); - } + checkSequenceSize(size); self.realloc(size); }) .function("size", &css::uno::Sequence<T>::getLength) |