From cae99471adc7532db34c365ee729a1ea7ffea204 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 28 Apr 2016 17:33:05 +0300 Subject: CylindersModel: clamp the "cylinderuse" values If the value for "use" is negative or larger than the number of elements in "enum cylinderuse", later CylindersModel::data() can request a string in the lines of cylinderuse_text[cyl->cylinder_use], which can SIGSEGV. Signed-off-by: Lubomir I. Ivanov Signed-off-by: Dirk Hohndel --- qt-models/cylindermodel.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'qt-models') diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index b1ce0be24..350d15aa4 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -273,7 +273,10 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in break; case USE: if (CHANGED()) { - cyl->cylinder_use = (enum cylinderuse)vString.toInt(); + int use = vString.toInt(); + if (use > NUM_GAS_USE - 1 || use < 0) + use = 0; + cyl->cylinder_use = (enum cylinderuse)use; changed = true; } break; -- cgit v1.2.3-70-g09d2