Skip to content

Commit

Permalink
Merge pull request #448 from nasa/fix-235-check-queue-maxdepth
Browse files Browse the repository at this point in the history
Fix #235, add check against OS_MAX_QUEUE_DEPTH
  • Loading branch information
astrogeco committed May 19, 2020
2 parents a7a9955 + 8304ec1 commit 2c69520
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/os/inc/osapi-os-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sys
* @retval #OS_ERR_NAME_TOO_LONG name length including null terminator greater than #OS_MAX_API_NAME
* @retval #OS_ERR_NO_FREE_IDS if there are already the max queues created
* @retval #OS_ERR_NAME_TAKEN if the name is already being used on another queue
* @retval #OS_QUEUE_INVALID_SIZE if the queue depth exceeds the limit
* @retval #OS_ERROR if the OS create call fails
*/
int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name,
Expand Down
5 changes: 5 additions & 0 deletions src/os/shared/src/osapi-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, uint32 queue_dep
return OS_ERR_NAME_TOO_LONG;
}

if ( queue_depth > OS_QUEUE_MAX_DEPTH )
{
return OS_QUEUE_INVALID_SIZE;
}

/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, queue_name, &local_id, &record);
if(return_code == OS_SUCCESS)
Expand Down
4 changes: 4 additions & 0 deletions src/unit-test-coverage/shared/src/coveragetest-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ void Test_OS_QueueCreate(void)
actual = OS_QueueCreate(&objid, "UT", 0, 0,0);
UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_ERR_NAME_TOO_LONG", (long)actual);
UT_ClearForceFail(UT_KEY(OCS_strlen));

expected = OS_QUEUE_INVALID_SIZE;
actual = OS_QueueCreate(&objid, "UT", 1 + OS_QUEUE_MAX_DEPTH, 0,0);
UtAssert_True(actual == expected, "OS_QueueCreate() (%ld) == OS_QUEUE_INVALID_SIZE", (long)actual);
}

void Test_OS_QueueDelete(void)
Expand Down

0 comments on commit 2c69520

Please sign in to comment.