Skip to content

Commit

Permalink
Fix nasa#742, make sure all pointers are checked for null
Browse files Browse the repository at this point in the history
  • Loading branch information
zanzaben committed Jan 20, 2021
1 parent bfca5b2 commit abebf1c
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/os/shared/src/osapi-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int32 OS_BinSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_initia
OS_object_token_t token;
OS_bin_sem_internal_record_t *binsem;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(sem_id);
OS_CHECK_APINAME(sem_name);

Expand Down Expand Up @@ -255,7 +255,7 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
{
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(sem_id);
OS_CHECK_POINTER(sem_name);

Expand All @@ -278,7 +278,7 @@ int32 OS_BinSemGetInfo(osal_id_t sem_id, OS_bin_sem_prop_t *bin_prop)
OS_object_token_t token;
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(bin_prop);

memset(bin_prop, 0, sizeof(OS_bin_sem_prop_t));
Expand Down
4 changes: 2 additions & 2 deletions src/os/shared/src/osapi-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*-----------------------------------------------------------------*/
int32 OS_GetLocalTime(OS_time_t *time_struct)
{
/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(time_struct);

return OS_GetLocalTime_Impl(time_struct);
Expand All @@ -67,7 +67,7 @@ int32 OS_GetLocalTime(OS_time_t *time_struct)
*-----------------------------------------------------------------*/
int32 OS_SetLocalTime(const OS_time_t *time_struct)
{
/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(time_struct);

return OS_SetLocalTime_Impl(time_struct);
Expand Down
9 changes: 9 additions & 0 deletions src/os/shared/src/osapi-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data)
{
int32 status;

/*
* Check parameters
*
* Note "data" is not checked, because in certain configurations it can be validly null.
*/

if (OS_SharedGlobalVars.EventHandler != NULL)
{
status = OS_SharedGlobalVars.EventHandler(event, object_id, data);
Expand Down Expand Up @@ -276,6 +282,9 @@ void OS_CleanUpObject(osal_id_t object_id, void *arg)
{
uint32 *ObjectCount;

/* TODO: void pointer, https://github.com/nasa/osal/issues/765 */
//OS_CHECK_POINTER(arg);

ObjectCount = (uint32 *)arg;
++(*ObjectCount);
switch (OS_IdentifyObject(object_id))
Expand Down
6 changes: 3 additions & 3 deletions src/os/shared/src/osapi-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int32 OS_CountSemCreate(osal_id_t *sem_id, const char *sem_name, uint32 sem_init
OS_object_token_t token;
OS_count_sem_internal_record_t *countsem;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(sem_id);
OS_CHECK_APINAME(sem_name);

Expand Down Expand Up @@ -224,7 +224,7 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
{
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(sem_id);
OS_CHECK_POINTER(sem_name);

Expand All @@ -247,7 +247,7 @@ int32 OS_CountSemGetInfo(osal_id_t sem_id, OS_count_sem_prop_t *count_prop)
OS_object_token_t token;
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(count_prop);

memset(count_prop, 0, sizeof(OS_count_sem_prop_t));
Expand Down
4 changes: 4 additions & 0 deletions src/os/shared/src/osapi-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *For
{
va_list va;

/* TODO: void pointer, https://github.com/nasa/osal/issues/765 */
//OS_CHECK_POINTER(Func);
//OS_CHECK_POINTER(Format);

if (OS_SharedGlobalVars.DebugLevel >= Level)
{
va_start(va, Format);
Expand Down
4 changes: 2 additions & 2 deletions src/os/shared/src/osapi-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path)
OS_dir_internal_record_t *dir;
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(dir_id);

return_code = OS_TranslatePath(path, local_path);
Expand Down Expand Up @@ -183,7 +183,7 @@ int32 OS_DirectoryRead(osal_id_t dir_id, os_dirent_t *dirent)
OS_object_token_t token;
int32 return_code;

/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(dirent);

/* Make sure the file descriptor is legit before using it */
Expand Down
1 change: 1 addition & 0 deletions src/os/shared/src/osapi-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name)
uint32 return_code;
const OS_ErrorTable_Entry_t *Error;

/* Check parameters */
OS_CHECK_POINTER(err_name);

Error = OS_GLOBAL_ERROR_NAME_TABLE;
Expand Down
3 changes: 3 additions & 0 deletions src/os/shared/src/osapi-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc
OS_object_token_t token;
OS_stream_internal_record_t *stream;

/* Check parameters */
OS_CHECK_POINTER(filedes);

/*
Expand Down Expand Up @@ -630,6 +631,7 @@ int32 OS_FileOpenCheck(const char *Filename)
OS_object_iter_t iter;
OS_stream_internal_record_t *stream;

/* Check parameters */
OS_CHECK_POINTER(Filename);

return_code = OS_ERROR;
Expand Down Expand Up @@ -666,6 +668,7 @@ int32 OS_CloseFileByName(const char *Filename)
OS_object_iter_t iter;
OS_stream_internal_record_t *stream;

/* Check parameters */
OS_CHECK_POINTER(Filename);

return_code = OS_FS_ERR_PATH_INVALID;
Expand Down
14 changes: 12 additions & 2 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const char OS_FILESYS_RAMDISK_VOLNAME_PREFIX[] = "RAM";
*-----------------------------------------------------------------*/
bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj)
{
/* Check parameters */
OS_CHECK_POINTER(obj);

return !OS_ObjectIdDefined(obj->active_id);
}

Expand All @@ -91,6 +94,10 @@ bool OS_FileSysFilterFree(void *ref, const OS_object_token_t *token, const OS_co
*-----------------------------------------------------------------*/
bool OS_FileSys_FindVirtMountPoint(void *ref, const OS_object_token_t *token, const OS_common_record_t *obj)
{
/* Check parameters */
OS_CHECK_POINTER(ref);
OS_CHECK_POINTER(token);

OS_filesys_internal_record_t *filesys;
const char * target = (const char *)ref;
size_t mplen;
Expand Down Expand Up @@ -126,7 +133,9 @@ int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char *fs
OS_object_token_t token;

/*
** Check parameters
* Check parameters
*
* Note "address" is not checked, because in certain configurations it can be validly null.
*/
OS_CHECK_STRING(fsdevname, sizeof(filesys->device_name), OS_FS_ERR_PATH_TOO_LONG);
OS_CHECK_STRING(fsvolname, sizeof(filesys->volume_name), OS_FS_ERR_PATH_TOO_LONG);
Expand Down Expand Up @@ -350,6 +359,7 @@ int32 OS_rmfs(const char *devname)
int32 return_code;
OS_object_token_t token;

/* Check parameters */
OS_CHECK_PATHNAME(devname);

return_code = OS_ObjectIdGetByName(OS_LOCK_MODE_EXCLUSIVE, LOCAL_OBJID_TYPE, devname, &token);
Expand Down Expand Up @@ -782,7 +792,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath)
/*
** Check to see if the path pointers are NULL
*/
/* Check inputs */
/* Check parameters */
OS_CHECK_POINTER(VirtualPath);
OS_CHECK_POINTER(LocalPath);

Expand Down
1 change: 1 addition & 0 deletions src/os/shared/src/osapi-heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*-----------------------------------------------------------------*/
int32 OS_HeapGetInfo(OS_heap_prop_t *heap_prop)
{
/* Check parameters */
OS_CHECK_POINTER(heap_prop);

return OS_HeapGetInfo_Impl(heap_prop);
Expand Down
Loading

0 comments on commit abebf1c

Please sign in to comment.