mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
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:
@@ -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)
|
void UI_tab_widget::set_selected(size_t selected)
|
||||||
{
|
{
|
||||||
|
if (selected >= m_tab_names.size())
|
||||||
|
return;
|
||||||
m_selected_tab = selected;
|
m_selected_tab = selected;
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
emit changed(m_selected_tab);
|
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())
|
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;
|
m_tab_visible.at(index) = visible;
|
||||||
emit ui_changed();
|
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)
|
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);
|
// Only allow known tab amount from constructor
|
||||||
}
|
return;
|
||||||
if (index >= m_tab_visible.size())
|
|
||||||
{
|
|
||||||
m_tab_visible.resize(index + 1, true);
|
|
||||||
}
|
}
|
||||||
m_tab_names.at(index) = name;
|
m_tab_names.at(index) = name;
|
||||||
emit ui_changed();
|
emit ui_changed();
|
||||||
@@ -85,6 +85,7 @@ void UI_tab_widget::from_json(const json &j)
|
|||||||
}
|
}
|
||||||
m_selected_tab = j.at("selected");
|
m_selected_tab = j.at("selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
json UI_tab_widget::to_json(size_t id) const
|
json UI_tab_widget::to_json(size_t id) const
|
||||||
{
|
{
|
||||||
json j = UI_item::to_json(id);
|
json j = UI_item::to_json(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user