From 112e6c77f14b72fd65018a417618660162dc26dc Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Sat, 8 Jun 2024 13:32:37 +0300 Subject: [PATCH] UI: TrayIcon: Add checks --- src/ui/form/opt/pages/optionspage.cpp | 2 +- src/ui/form/tray/trayicon.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui/form/opt/pages/optionspage.cpp b/src/ui/form/opt/pages/optionspage.cpp index 30e8fae3..ae2d377d 100644 --- a/src/ui/form/opt/pages/optionspage.cpp +++ b/src/ui/form/opt/pages/optionspage.cpp @@ -47,7 +47,7 @@ void updateComboBox( { int index = 0; for (const QString &name : names) { - const QString iconPath = iconPaths.at(index); + const QString &iconPath = iconPaths.at(index); c->setItemText(index, name); c->setItemIcon(index, IconCache::icon(iconPath)); diff --git a/src/ui/form/tray/trayicon.cpp b/src/ui/form/tray/trayicon.cpp index 3552dfaf..73cc6590 100644 --- a/src/ui/form/tray/trayicon.cpp +++ b/src/ui/form/tray/trayicon.cpp @@ -487,8 +487,12 @@ void TrayIcon::setupTrayMenuBlockTraffic() int index = 0; const QStringList iconPaths = FirewallConf::blockTrafficIconPaths(); for (const QString &name : FirewallConf::blockTrafficNames()) { - const QString iconPath = iconPaths.at(index); - const auto &iniKey = blockTrafficIniKeys[index]; + const QString &iconPath = iconPaths.at(index); + + if (Q_UNLIKELY(index >= std::size(blockTrafficIniKeys))) + break; + + const char *iniKey = blockTrafficIniKeys[index]; QAction *a = addAction(m_blockTrafficMenu, iconPath, /*receiver=*/nullptr, /*member=*/nullptr, ActionNone, /*checkable=*/true); @@ -520,8 +524,12 @@ void TrayIcon::setupTrayMenuFilterMode() int index = 0; const QStringList iconPaths = FirewallConf::filterModeIconPaths(); for (const QString &name : FirewallConf::filterModeNames()) { - const QString iconPath = iconPaths.at(index); - const auto &iniKey = filterModeIniKeys[index]; + const QString &iconPath = iconPaths.at(index); + + if (Q_UNLIKELY(index >= std::size(filterModeIniKeys))) + break; + + const char *iniKey = filterModeIniKeys[index]; QAction *a = addAction(m_filterModeMenu, iconPath, /*receiver=*/nullptr, /*member=*/nullptr, ActionNone, /*checkable=*/true);