Skip to content

Commit 739c400

Browse files
author
Kevin Moloney
committed
Fix Klocwork#543,544: Buffer overflow/null pointer
* Added a check to ensure array does not access index value of -1. * Added a check for this null pointer. Signed-off-by: Kevin Moloney <kevin.moloney@emutex.com>
1 parent dd4845e commit 739c400

File tree

1 file changed

+5
-2
lines changed
  • system/libarc32_arduino101/framework/src/infra

1 file changed

+5
-2
lines changed

system/libarc32_arduino101/framework/src/infra/port.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ uint16_t port_alloc(void * queue)
136136
{
137137
struct port * ret = NULL;
138138
uint32_t flags = interrupt_lock();
139-
if (registered_port_count < MAX_PORTS) {
139+
if ((registered_port_count < MAX_PORTS) && (registered_port_count >= 0)) {
140140
ports[registered_port_count].id = registered_port_count + 1; /* don't use 0 as port.*/
141141
ports[registered_port_count].cpu_id = get_cpu_id(); /* is overwritten in case of ipc */
142142
ports[registered_port_count].queue = queue;
@@ -150,7 +150,10 @@ uint16_t port_alloc(void * queue)
150150
panic(E_OS_ERR_NO_MEMORY);
151151
}
152152
interrupt_unlock(flags);
153-
return ret->id;
153+
if (ret != NULL)
154+
return ret->id;
155+
else
156+
return 0;
154157
}
155158
#else
156159
uint16_t port_alloc(void *queue)

0 commit comments

Comments
 (0)