Skip to content

Commit

Permalink
Merge pull request #766 from zanzaben/fix742_null_pointer_cleanup
Browse files Browse the repository at this point in the history
Fix #742, make sure all pointers are checked for null
  • Loading branch information
astrogeco authored Feb 3, 2021
2 parents 1ebb788 + 3b2c729 commit 6787dfe
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 39 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
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: 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
9 changes: 6 additions & 3 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ 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 +352,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 @@ -786,7 +789,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
27 changes: 14 additions & 13 deletions src/os/shared/src/osapi-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ typedef struct
void * user_arg;
} OS_creator_filter_t;


/*
* Global ID storage tables
*/
Expand Down Expand Up @@ -270,7 +269,6 @@ int32 OS_ForEachDoCallback(osal_id_t obj_id, void *ref)
return OS_SUCCESS;
}


/*----------------------------------------------------------------
*
* Function: OS_ObjectIdGlobalFromToken
Expand Down Expand Up @@ -747,16 +745,17 @@ void OS_Lock_Global(OS_object_token_t *token)
* This makes it different for every operation, and different depending
* on what task is calling the function.
*/
token->lock_key.key_value = OS_LOCK_KEY_FIXED_VALUE |
((OS_ObjectIdToInteger(self_task_id) ^ objtype->transaction_count) & 0xFFFFFF);
token->lock_key.key_value =
OS_LOCK_KEY_FIXED_VALUE | ((OS_ObjectIdToInteger(self_task_id) ^ objtype->transaction_count) & 0xFFFFFF);

++objtype->transaction_count;

if (objtype->owner_key.key_value != 0)
{
/* this is almost certainly a bug */
OS_DEBUG("ERROR: global %u acquired by task 0x%lx when already assigned key 0x%lx\n", (unsigned int)token->obj_type,
OS_ObjectIdToInteger(self_task_id), (unsigned long)objtype->owner_key.key_value);
OS_DEBUG("ERROR: global %u acquired by task 0x%lx when already assigned key 0x%lx\n",
(unsigned int)token->obj_type, OS_ObjectIdToInteger(self_task_id),
(unsigned long)objtype->owner_key.key_value);
}
else
{
Expand All @@ -765,8 +764,8 @@ void OS_Lock_Global(OS_object_token_t *token)
}
else
{
OS_DEBUG("ERROR: cannot lock global %u for mode %u\n",
(unsigned int)token->obj_type, (unsigned int)token->lock_mode);
OS_DEBUG("ERROR: cannot lock global %u for mode %u\n", (unsigned int)token->obj_type,
(unsigned int)token->lock_mode);
}
}

Expand Down Expand Up @@ -795,8 +794,9 @@ void OS_Unlock_Global(OS_object_token_t *token)
objtype->owner_key.key_value != token->lock_key.key_value)
{
/* this is almost certainly a bug */
OS_DEBUG("ERROR: global %u released using mismatched key=0x%lx expected=0x%lx\n", (unsigned int)token->obj_type,
(unsigned long)token->lock_key.key_value, (unsigned long)objtype->owner_key.key_value);
OS_DEBUG("ERROR: global %u released using mismatched key=0x%lx expected=0x%lx\n",
(unsigned int)token->obj_type, (unsigned long)token->lock_key.key_value,
(unsigned long)objtype->owner_key.key_value);
}

objtype->owner_key = OS_LOCK_KEY_INVALID;
Expand All @@ -806,8 +806,8 @@ void OS_Unlock_Global(OS_object_token_t *token)
}
else
{
OS_DEBUG("ERROR: cannot unlock global %u for mode %u\n",
(unsigned int)token->obj_type, (unsigned int)token->lock_mode);
OS_DEBUG("ERROR: cannot unlock global %u for mode %u\n", (unsigned int)token->obj_type,
(unsigned int)token->lock_mode);
}
}

Expand Down Expand Up @@ -1433,7 +1433,8 @@ void OS_ForEachObject(osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
void OS_ForEachObjectOfType(osal_objtype_t idtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr, void *callback_arg)
void OS_ForEachObjectOfType(osal_objtype_t idtype, osal_id_t creator_id, OS_ArgCallback_t callback_ptr,
void *callback_arg)
{
OS_object_iter_t iter;
OS_creator_filter_t filter;
Expand Down
14 changes: 6 additions & 8 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f
OS_module_internal_record_t *module;

/*
** Check parameters
**
** Note "filename" is not checked, because in certain configurations it can be validly
** null. filename is checked for NULL-ness by the OS_TranslatePath() later.
*/
* Check parameters
*
* Note "filename" is not checked, because in certain configurations it can be validly
* null. filename is checked for NULL-ness by the OS_TranslatePath() later.
*/
OS_CHECK_POINTER(module_id);
OS_CHECK_APINAME(module_name);

Expand Down Expand Up @@ -454,9 +454,7 @@ int32 OS_SymbolTableDump(const char *filename, size_t SizeLimit)
char translated_path[OS_MAX_LOCAL_PATH_LEN];
OS_object_token_t token;

/*
** Check parameters
*/
/* Check parameters */
OS_CHECK_POINTER(filename);

/*
Expand Down
2 changes: 2 additions & 0 deletions src/os/shared/src/osapi-printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ void OS_printf(const char *String, ...)
char msg_buffer[OS_BUFFER_SIZE];
int actualsz;

BUGCHECK((String) != NULL, )

if (!OS_SharedGlobalVars.Initialized)
{
/*
Expand Down
6 changes: 6 additions & 0 deletions src/os/shared/src/osapi-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs)
{
int32 return_code;

/*
* Check parameters
*
* Note "ReadSet" and "WriteSet" are not checked, because in certain configurations they can be validly null.
*/

/*
* This does not currently increment any refcounts.
* That means a file/socket can be closed while actively inside a
Expand Down
11 changes: 10 additions & 1 deletion src/os/shared/src/osapi-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ int32 OS_SocketRecvFrom(osal_id_t sock_id, void *buffer, size_t buflen, OS_SockA
OS_object_token_t token;
int32 return_code;

/* Check Parameters */
/*
* Check parameters
*
* Note "RemoteAddr" is not checked, because in certain configurations it can be validly null.
*/
OS_CHECK_POINTER(buffer);
OS_CHECK_SIZE(buflen);

Expand Down Expand Up @@ -493,6 +497,7 @@ int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop)
*-----------------------------------------------------------------*/
int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain)
{
/* Check parameters */
OS_CHECK_POINTER(Addr);

return OS_SocketAddrInit_Impl(Addr, Domain);
Expand All @@ -508,6 +513,7 @@ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain)
*-----------------------------------------------------------------*/
int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Addr)
{
/* Check parameters */
OS_CHECK_POINTER(Addr);
OS_CHECK_POINTER(buffer);
OS_CHECK_SIZE(buflen);
Expand All @@ -525,6 +531,7 @@ int32 OS_SocketAddrToString(char *buffer, size_t buflen, const OS_SockAddr_t *Ad
*-----------------------------------------------------------------*/
int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string)
{
/* Check parameters */
OS_CHECK_POINTER(Addr);
OS_CHECK_POINTER(string);

Expand All @@ -541,6 +548,7 @@ int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string)
*-----------------------------------------------------------------*/
int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr)
{
/* Check parameters */
OS_CHECK_POINTER(Addr);
OS_CHECK_POINTER(PortNum);

Expand All @@ -557,6 +565,7 @@ int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr)
*-----------------------------------------------------------------*/
int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum)
{
/* Check parameters */
OS_CHECK_POINTER(Addr);

return OS_SocketAddrSetPort_Impl(Addr, PortNum);
Expand Down
7 changes: 6 additions & 1 deletion src/os/shared/src/osapi-task.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ int32 OS_TaskCreate(osal_id_t *task_id, const char *task_name, osal_task_entry f
OS_object_token_t token;
OS_task_internal_record_t *task;

/* Check for NULL pointers */
/*
* Check parameters
*
* Note "stack_pointer" is not checked, because in certain configurations it can be validly null.
*/
OS_CHECK_POINTER(task_id);
OS_CHECK_POINTER(function_pointer);
OS_CHECK_APINAME(task_name);
Expand Down Expand Up @@ -381,6 +385,7 @@ int32 OS_TaskGetIdByName(osal_id_t *task_id, const char *task_name)
{
int32 return_code;

/* Check parameters */
OS_CHECK_POINTER(task_id);
OS_CHECK_POINTER(task_name);

Expand Down
5 changes: 4 additions & 1 deletion src/os/shared/src/osapi-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ static int32 OS_DoTimerAdd(osal_id_t *timer_id, const char *timer_name, osal_id_
OS_timebase_internal_record_t *timebase;

/*
** Check Parameters
* Check parameters
*
* Note "callback_arg" is not checked, because in certain configurations it can be validly null.
*/
OS_CHECK_POINTER(timer_id);
OS_CHECK_APINAME(timer_name);
Expand Down Expand Up @@ -478,6 +480,7 @@ int32 OS_TimerGetIdByName(osal_id_t *timer_id, const char *timer_name)
int32 return_code;
osal_objtype_t objtype;

/* Check parameters */
OS_CHECK_POINTER(timer_id);
OS_CHECK_POINTER(timer_name);

Expand Down
1 change: 1 addition & 0 deletions src/os/shared/src/osapi-timebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ int32 OS_TimeBaseGetIdByName(osal_id_t *timer_id, const char *timebase_name)
int32 return_code;
osal_objtype_t objtype;

/* Check parameters */
OS_CHECK_POINTER(timer_id);
OS_CHECK_APINAME(timebase_name);

Expand Down
Loading

0 comments on commit 6787dfe

Please sign in to comment.