From 3d6c376b4751c39843b8d775adf8706671ac9615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Mi=C5=A1i=C4=87?= Date: Fri, 19 May 2023 16:35:51 +0200 Subject: [PATCH] dataman: add guards for max item value --- src/modules/dataman/dataman.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/modules/dataman/dataman.cpp b/src/modules/dataman/dataman.cpp index 936b55271b..f4345cc685 100644 --- a/src/modules/dataman/dataman.cpp +++ b/src/modules/dataman/dataman.cpp @@ -200,6 +200,10 @@ calculate_offset(dm_item_t item, unsigned index) /* write to the data manager RAM buffer */ static ssize_t _ram_write(dm_item_t item, unsigned index, const void *buf, size_t count) { + if (item >= DM_KEY_NUM_KEYS) { + return -1; + } + /* Get the offset for this item */ int offset = calculate_offset(item, index); @@ -237,6 +241,10 @@ static ssize_t _ram_write(dm_item_t item, unsigned index, const void *buf, size_ static ssize_t _file_write(dm_item_t item, unsigned index, const void *buf, size_t count) { + if (item >= DM_KEY_NUM_KEYS) { + return -1; + } + unsigned char buffer[g_per_item_size_with_hdr[item]]; /* Get the offset for this item */ @@ -310,6 +318,10 @@ _file_write(dm_item_t item, unsigned index, const void *buf, size_t count) /* Retrieve from the data manager RAM buffer*/ static ssize_t _ram_read(dm_item_t item, unsigned index, void *buf, size_t count) { + if (item >= DM_KEY_NUM_KEYS) { + return -1; + } + /* Get the offset for this item */ int offset = calculate_offset(item, index); @@ -426,6 +438,10 @@ _file_read(dm_item_t item, unsigned index, void *buf, size_t count) static int _ram_clear(dm_item_t item) { + if (item >= DM_KEY_NUM_KEYS) { + return -1; + } + int i; int result = 0; @@ -456,6 +472,10 @@ static int _ram_clear(dm_item_t item) static int _file_clear(dm_item_t item) { + if (item >= DM_KEY_NUM_KEYS) { + return -1; + } + int i, result = 0; /* Get the offset of 1st item of this type */