1
0
Fork 0

CO_SDOclient: static analysis: potential out of bounds pointer access [MISRA 2012 Rule 18.1, required]

This commit is contained in:
temi54c1l8 2024-06-27 08:55:44 +02:00
parent 646e367ae1
commit b39334d9c3
2 changed files with 9 additions and 9 deletions

View file

@ -29,7 +29,7 @@
#if ((CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_ENABLE) != 0
/* verify configuration */
#if CO_CONFIG_SDO_CLI_BUFFER_SIZE < 7
#if CO_CONFIG_SDO_CLI_BUFFER_SIZE < 7U
#error CO_CONFIG_SDO_CLI_BUFFER_SIZE must be set to 7 or more.
#endif
#if ((CO_CONFIG_FIFO) & CO_CONFIG_FIFO_ENABLE) == 0
@ -290,7 +290,7 @@ CO_ReturnError_t CO_SDOclient_init(CO_SDOclient_t *SDO_C,
/* prepare circular fifo buffer */
CO_fifo_init(&SDO_C->bufFifo, SDO_C->buf,
CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1);
CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1U);
/* Get parameters from Object Dictionary (initial values) */
uint8_t maxSubIndex, nodeIDOfTheSDOServer;
@ -573,13 +573,13 @@ CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C,
/* write data, in several passes if necessary */
if (SDO_C->OD_IO.write != NULL) {
size_t count = CO_fifo_getOccupied(&SDO_C->bufFifo);
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 2];
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 2U];
(void)CO_fifo_read(&SDO_C->bufFifo, buf, count, NULL);
SDO_C->sizeTran += count;
/* error: no data */
if (count == 0U) {
if ((count == 0U) || (count > CO_CONFIG_SDO_CLI_BUFFER_SIZE)){
abortCode = CO_SDO_AB_DEVICE_INCOMPAT;
ret = CO_SDO_RT_endedWithClientAbort;
}
@ -1298,7 +1298,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
OD_size_t countBuf = ((countData > 0U) && (countData <= countFifo))
? countData : (OD_size_t)countFifo;
OD_size_t countRd = 0;
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1];
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1U];
/* load data from OD variable into the buffer */
CO_LOCK_OD(SDO_C->CANdevTx);
@ -1312,7 +1312,7 @@ CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C,
}
else {
/* if data is string, send only data up to null termination */
if ((countRd > 0U)
if ((countRd > 0U) && (countRd <= CO_CONFIG_SDO_CLI_BUFFER_SIZE)
&& ((SDO_C->OD_IO.stream.attribute & (OD_attr_t)ODA_STR) != 0U)
) {
buf[countRd] = 0; /* (buf is one byte larger) */

View file

@ -38,9 +38,9 @@
#endif
#ifndef CO_CONFIG_SDO_CLI_BUFFER_SIZE
#if ((CO_CONFIG_SDO_CLI) & CO_CONFIG_SDO_CLI_BLOCK) != 0
#define CO_CONFIG_SDO_CLI_BUFFER_SIZE 1000
#define CO_CONFIG_SDO_CLI_BUFFER_SIZE 1000U
#else
#define CO_CONFIG_SDO_CLI_BUFFER_SIZE 32
#define CO_CONFIG_SDO_CLI_BUFFER_SIZE 32U
#endif
#endif
@ -228,7 +228,7 @@ typedef struct {
CO_fifo_t bufFifo;
/** Data buffer of usable size @ref CO_CONFIG_SDO_CLI_BUFFER_SIZE, used
* inside bufFifo. Must be one byte larger for fifo usage. */
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1];
uint8_t buf[CO_CONFIG_SDO_CLI_BUFFER_SIZE + 1U];
/** Indicates, if new SDO message received from CAN bus. It is not cleared,
* until received message is completely processed. */
volatile void *CANrxNew;