Guards against out-of-bounds access in tab widget

Adds bounds checking to `set_selected`, `set_visible`, and
`set_tab_name` methods to prevent out-of-bounds access on the tab
data structures.
Removes unnecessary resizing logic as tab size is defined in constructor.
This commit is contained in:
2026-02-14 14:32:19 +01:00
parent baaf33361e
commit d0c392ca0e
+8 -7
View File
@@ -14,6 +14,8 @@ UI_tab_widget::UI_tab_widget(std::vector<std::string> tab_names, size_t selected
void UI_tab_widget::set_selected(size_t selected)
{
if (selected >= m_tab_names.size())
return;
m_selected_tab = selected;
emit ui_changed();
emit changed(m_selected_tab);
@@ -27,7 +29,8 @@ void UI_tab_widget::set_visible(size_t index, bool visible)
{
if (index >= m_tab_visible.size())
{
m_tab_visible.resize(index + 1);
// Only allow known tab amount from constructor
return;
}
m_tab_visible.at(index) = visible;
emit ui_changed();
@@ -39,13 +42,10 @@ bool UI_tab_widget::visible(size_t index) const
void UI_tab_widget::set_tab_name(size_t index, std::string name)
{
if (index >= m_tab_names.size())
if (index >= m_tab_names.size() || index >= m_tab_visible.size())
{
m_tab_names.resize(index + 1);
}
if (index >= m_tab_visible.size())
{
m_tab_visible.resize(index + 1, true);
// Only allow known tab amount from constructor
return;
}
m_tab_names.at(index) = name;
emit ui_changed();
@@ -85,6 +85,7 @@ void UI_tab_widget::from_json(const json &j)
}
m_selected_tab = j.at("selected");
}
json UI_tab_widget::to_json(size_t id) const
{
json j = UI_item::to_json(id);