From 769aca9e956cd4bb7cc97be813968348f5e7f3d2 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Tue, 19 Jun 2018 03:19:56 +0300 Subject: equipment: sanitize 'tank_info' loop limits In a number of places the global 'tank_info' array is being iterated based on a 'tank_info[idx].name != NULL' condition. This is dangerous because if the user has added a lot of tanks, such loops can reach 'tank_info[MAX_TANK_INFO]'. This is an out of bounds read and if the 'name' pointer there happens to be non-NULL, passing that address to a peace of code that tries to read it (like strlen()) would either SIGSEGV or have undefined behavior. Clamp all loops that iterate 'tank_info' to MAX_TANK_INFO. Signed-off-by: Lubomir I. Ivanov --- desktop-widgets/preferences/preferences_defaults.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'desktop-widgets/preferences') diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index 4500ecac2..e0a24530a 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -52,7 +52,7 @@ void PreferencesDefaults::refreshSettings() ui->localDefaultFile->setChecked(prefs.default_file_behavior == LOCAL_DEFAULT_FILE); ui->default_cylinder->clear(); - for (int i = 0; tank_info[i].name != NULL; i++) { + for (int i = 0; tank_info[i].name != NULL && i < MAX_TANK_INFO; i++) { ui->default_cylinder->addItem(tank_info[i].name); if (prefs.default_cylinder && strcmp(tank_info[i].name, prefs.default_cylinder) == 0) ui->default_cylinder->setCurrentIndex(i); -- cgit v1.2.3-70-g09d2