mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
tankinfomodel.cpp: clamp row index to [0 - MAX_TANK_INFO]
MAX_TANK_INFO is a new macro in dive.h to define the maximum number of tank_info_t objects. TankInfoModel's data() and setData() now check for valid row indexes before accessing the tank_info[] array directly. Without this patch TankInfoMode::data() can cause a SIGSEGV. Reported-by: Pedro Neves <nevesdiver@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
85021b94b1
commit
27deb317b0
2 changed files with 7 additions and 2 deletions
|
@ -28,6 +28,10 @@ bool TankInfoModel::setData(const QModelIndex &index, const QVariant &value, int
|
|||
{
|
||||
//WARN Seems wrong, we need to check for role == Qt::EditRole
|
||||
Q_UNUSED(role);
|
||||
|
||||
if (index.row() < 0 || index.row() > MAX_TANK_INFO - 1)
|
||||
return false;
|
||||
|
||||
struct tank_info_t *info = &tank_info[index.row()];
|
||||
switch (index.column()) {
|
||||
case DESCRIPTION:
|
||||
|
@ -51,7 +55,7 @@ void TankInfoModel::clear()
|
|||
QVariant TankInfoModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QVariant ret;
|
||||
if (!index.isValid()) {
|
||||
if (!index.isValid() || index.row() < 0 || index.row() > MAX_TANK_INFO - 1) {
|
||||
return ret;
|
||||
}
|
||||
if (role == Qt::FontRole) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue