check value range before accessing a group objects

This commit is contained in:
Luas Lichtl 2024-08-30 18:46:24 +02:00
parent 150f3fc24b
commit 7e6de21a95
3 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,7 @@
BauSystemBDevice::BauSystemBDevice(Platform& platform) : BauSystemBDevice::BauSystemBDevice(Platform& platform) :
BauSystemB(platform), BauSystemB(platform),
_addrTable(_memory), _addrTable(_memory),
_assocTable(_memory), _groupObjTable(_memory), _assocTable(_memory), _groupObjTable(_memory, platform),
#ifdef USE_DATASECURE #ifdef USE_DATASECURE
_appLayer(_deviceObj, _secIfObj, *this), _appLayer(_deviceObj, _secIfObj, *this),
#else #else

View File

@ -5,8 +5,8 @@
#include "bits.h" #include "bits.h"
#include "data_property.h" #include "data_property.h"
GroupObjectTableObject::GroupObjectTableObject(Memory& memory) GroupObjectTableObject::GroupObjectTableObject(Memory& memory, Platform& platform)
: TableObject(memory) : TableObject(memory), _platform(platform)
{ {
Property* properties[] Property* properties[]
{ {
@ -30,6 +30,11 @@ uint16_t GroupObjectTableObject::entryCount()
GroupObject& GroupObjectTableObject::get(uint16_t asap) GroupObject& GroupObjectTableObject::get(uint16_t asap)
{ {
if ((asap == 0) || (asap > UINT8_MAX)) {
println("Group Object ID out of range!");
_platform.fatalError();
}
return _groupObjects[asap - 1]; return _groupObjects[asap - 1];
} }

View File

@ -2,13 +2,14 @@
#include "table_object.h" #include "table_object.h"
#include "group_object.h" #include "group_object.h"
#include "platform.h"
class GroupObjectTableObject : public TableObject class GroupObjectTableObject : public TableObject
{ {
friend class GroupObject; friend class GroupObject;
public: public:
GroupObjectTableObject(Memory& memory); GroupObjectTableObject(Memory& memory, Platform& platform);
virtual ~GroupObjectTableObject(); virtual ~GroupObjectTableObject();
uint16_t entryCount(); uint16_t entryCount();
GroupObject& get(uint16_t asap); GroupObject& get(uint16_t asap);
@ -24,6 +25,7 @@ class GroupObjectTableObject : public TableObject
void freeGroupObjects(); void freeGroupObjects();
bool initGroupObjects(); bool initGroupObjects();
uint16_t* _tableData = 0; uint16_t* _tableData = 0;
Platform& _platform;
GroupObject* _groupObjects = 0; GroupObject* _groupObjects = 0;
uint16_t _groupObjectCount = 0; uint16_t _groupObjectCount = 0;
}; };