mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
equipment: sanitize 'ws_info' loop limits
Instead of a constant or a macro for the maximum number of 'ws_info' elements the 100 literal was used. Define MAX_WS_INFO in dive.h and use it everywhere. Also clamp loops that iterate `ws_info' to MAX_WS_INFO. Prevents potential out-of-bounds reading, similarly to the previous commit about 'tank_info'. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
parent
769aca9e95
commit
06a870c232
4 changed files with 12 additions and 12 deletions
|
@ -107,7 +107,7 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r
|
|||
if (!ws->description || gettextFromC::tr(ws->description) != vString) {
|
||||
// loop over translations to see if one matches
|
||||
int i = -1;
|
||||
while (ws_info[++i].name) {
|
||||
while (ws_info[++i].name && i < MAX_WS_INFO) {
|
||||
if (gettextFromC::tr(ws_info[i].name) == vString) {
|
||||
ws->description = copy_string(ws_info[i].name);
|
||||
break;
|
||||
|
|
|
@ -79,8 +79,8 @@ const QString &WSInfoModel::biggerString() const
|
|||
WSInfoModel::WSInfoModel() : rows(-1)
|
||||
{
|
||||
setHeaderDataStrings(QStringList() << tr("Description") << tr("kg"));
|
||||
struct ws_info_t *info = ws_info;
|
||||
for (info = ws_info; info->name; info++, rows++) {
|
||||
struct ws_info_t *info;
|
||||
for (info = ws_info; info->name && info < ws_info + MAX_WS_INFO; info++, rows++) {
|
||||
QString wsInfoName = gettextFromC::tr(info->name);
|
||||
if (wsInfoName.count() > biggerEntry.count())
|
||||
biggerEntry = wsInfoName;
|
||||
|
@ -94,11 +94,11 @@ WSInfoModel::WSInfoModel() : rows(-1)
|
|||
|
||||
void WSInfoModel::updateInfo()
|
||||
{
|
||||
struct ws_info_t *info = ws_info;
|
||||
struct ws_info_t *info;
|
||||
beginRemoveRows(QModelIndex(), 0, this->rows);
|
||||
endRemoveRows();
|
||||
rows = -1;
|
||||
for (info = ws_info; info->name; info++, rows++) {
|
||||
for (info = ws_info; info->name && info < ws_info + MAX_WS_INFO; info++, rows++) {
|
||||
QString wsInfoName = gettextFromC::tr(info->name);
|
||||
if (wsInfoName.count() > biggerEntry.count())
|
||||
biggerEntry = wsInfoName;
|
||||
|
@ -117,9 +117,8 @@ void WSInfoModel::update()
|
|||
endRemoveRows();
|
||||
rows = -1;
|
||||
}
|
||||
struct ws_info_t *info = ws_info;
|
||||
for (info = ws_info; info->name; info++, rows++)
|
||||
;
|
||||
struct ws_info_t *info;
|
||||
for (info = ws_info; info->name && info < ws_info + MAX_WS_INFO; info++, rows++);
|
||||
|
||||
if (rows > -1) {
|
||||
beginInsertRows(QModelIndex(), 0, rows);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue