From e95ced6d7addc4c3cb41cd7afdd5c3d68a7d6cc9 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 1 Nov 2019 17:36:08 +0100 Subject: [PATCH] Implemented #368: no segfault but exception if accessing invalid layer iterator --- src/laybasic/laybasic/layLayerProperties.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/laybasic/laybasic/layLayerProperties.cc b/src/laybasic/laybasic/layLayerProperties.cc index 7f17026fa..4e43e8838 100644 --- a/src/laybasic/laybasic/layLayerProperties.cc +++ b/src/laybasic/laybasic/layLayerProperties.cc @@ -28,10 +28,10 @@ #include "tlException.h" #include "tlExpression.h" #include "tlAssert.h" +#include "tlInternational.h" #include - namespace lay { @@ -1870,8 +1870,14 @@ LayerPropertiesList::insert (const LayerPropertiesIterator &iter, const LayerPro LayerPropertiesIterator parent = iter.parent (); if (parent.is_null ()) { + if (iter.child_index () > m_layer_properties.size ()) { + throw tl::Exception (tl::to_string (tr ("Iterator is out of range in LayerPropertiesList::insert"))); + } ret = &*(m_layer_properties.insert (m_layer_properties.begin () + iter.child_index (), node)); } else { + if (iter.child_index () > size_t (parent->end_children () - parent->begin_children ())) { + throw tl::Exception (tl::to_string (tr ("Iterator is out of range in LayerPropertiesList::insert"))); + } ret = &(parent->insert_child (parent->begin_children () + iter.child_index (), node)); } @@ -1889,8 +1895,14 @@ LayerPropertiesList::erase (const LayerPropertiesIterator &iter) std::pair pp = iter.parent_obj (); if (pp.first == 0) { + if (pp.second >= m_layer_properties.size ()) { + throw tl::Exception (tl::to_string (tr ("Iterator is out of range in LayerPropertiesList::erase"))); + } m_layer_properties.erase (m_layer_properties.begin () + pp.second); } else { + if (pp.second >= size_t (pp.first->end_children () - pp.first->begin_children ())) { + throw tl::Exception (tl::to_string (tr ("Iterator is out of range in LayerPropertiesList::erase"))); + } pp.first->erase_child (pp.first->begin_children () + pp.second); } }