Skip to content

Commit

Permalink
Fix #688, update all OSAL argument checks
Browse files Browse the repository at this point in the history
Use the new macros to validate arguments to OS API calls.

Also includes coverage test updates, which revealed some
areas where return types were not consistent, and the macro
makes them consistent now.
  • Loading branch information
jphickey committed Dec 15, 2020
1 parent f9e9b28 commit 5d22ca6
Show file tree
Hide file tree
Showing 44 changed files with 295 additions and 565 deletions.
27 changes: 8 additions & 19 deletions src/os/shared/src/osapi-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,9 @@ 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 for NULL pointers */
if (sem_id == NULL || sem_name == NULL)
{
return OS_INVALID_POINTER;
}

if (strlen(sem_name) >= OS_MAX_API_NAME)
{
return OS_ERR_NAME_TOO_LONG;
}
/* Check inputs */
OS_CHECK_POINTER(sem_id);
OS_CHECK_APINAME(sem_name);

/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token);
Expand Down Expand Up @@ -262,10 +255,9 @@ int32 OS_BinSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
{
int32 return_code;

if (sem_id == NULL || sem_name == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(sem_id);
OS_CHECK_POINTER(sem_name);

return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id);

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

/* Check parameters */
if (bin_prop == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(bin_prop);

memset(bin_prop, 0, sizeof(OS_bin_sem_prop_t));

Expand Down
12 changes: 4 additions & 8 deletions src/os/shared/src/osapi-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
*-----------------------------------------------------------------*/
int32 OS_GetLocalTime(OS_time_t *time_struct)
{
if (time_struct == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(time_struct);

return OS_GetLocalTime_Impl(time_struct);

Expand All @@ -69,10 +67,8 @@ int32 OS_GetLocalTime(OS_time_t *time_struct)
*-----------------------------------------------------------------*/
int32 OS_SetLocalTime(OS_time_t *time_struct)
{
if (time_struct == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(time_struct);

return OS_SetLocalTime_Impl(time_struct);

Expand Down
5 changes: 1 addition & 4 deletions src/os/shared/src/osapi-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,7 @@ int32 OS_API_Init(void)
*-----------------------------------------------------------------*/
int32 OS_RegisterEventHandler(OS_EventHandler_t handler)
{
if (handler == NULL)
{
return OS_INVALID_POINTER;
}
OS_CHECK_POINTER(handler);

OS_SharedGlobalVars.EventHandler = handler;
return OS_SUCCESS;
Expand Down
27 changes: 8 additions & 19 deletions src/os/shared/src/osapi-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,9 @@ 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 for NULL pointers */
if (sem_id == NULL || sem_name == NULL)
{
return OS_INVALID_POINTER;
}

if (strlen(sem_name) >= OS_MAX_API_NAME)
{
return OS_ERR_NAME_TOO_LONG;
}
/* Check inputs */
OS_CHECK_POINTER(sem_id);
OS_CHECK_APINAME(sem_name);

/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, sem_name, &token);
Expand Down Expand Up @@ -231,10 +224,9 @@ int32 OS_CountSemGetIdByName(osal_id_t *sem_id, const char *sem_name)
{
int32 return_code;

if (sem_id == NULL || sem_name == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(sem_id);
OS_CHECK_POINTER(sem_name);

return_code = OS_ObjectIdFindByName(LOCAL_OBJID_TYPE, sem_name, sem_id);

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

/* Check parameters */
if (count_prop == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(count_prop);

memset(count_prop, 0, sizeof(OS_count_sem_prop_t));

Expand Down
12 changes: 4 additions & 8 deletions src/os/shared/src/osapi-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path)
OS_dir_internal_record_t *dir;
int32 return_code;

if (dir_id == NULL || path == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(dir_id);

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

if (dirent == NULL)
{
return OS_INVALID_POINTER;
}
/* Check inputs */
OS_CHECK_POINTER(dirent);

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

if (err_name == NULL)
{
return OS_INVALID_POINTER;
}
OS_CHECK_POINTER(err_name);

Error = OS_GLOBAL_ERROR_NAME_TABLE;
while (Error->Name != NULL && Error->Number != error_num)
Expand Down
45 changes: 13 additions & 32 deletions src/os/shared/src/osapi-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,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;

if (filedes == NULL)
{
return OS_INVALID_POINTER;
}
OS_CHECK_POINTER(filedes);

/*
** Check for a valid access mode
Expand Down Expand Up @@ -266,10 +263,8 @@ int32 OS_TimedRead(osal_id_t filedes, void *buffer, size_t nbytes, int32 timeout
int32 return_code;

/* Check Parameters */
if (buffer == NULL || nbytes == 0)
{
return OS_INVALID_POINTER;
}
OS_CHECK_POINTER(buffer);
OS_CHECK_SIZE(nbytes);

return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token);
if (return_code == OS_SUCCESS)
Expand All @@ -296,10 +291,8 @@ int32 OS_TimedWrite(osal_id_t filedes, const void *buffer, size_t nbytes, int32
int32 return_code;

/* Check Parameters */
if (buffer == NULL || nbytes == 0)
{
return OS_INVALID_POINTER;
}
OS_CHECK_POINTER(buffer);
OS_CHECK_SIZE(nbytes);

return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, LOCAL_OBJID_TYPE, filedes, &token);
if (return_code == OS_SUCCESS)
Expand Down Expand Up @@ -373,10 +366,8 @@ int32 OS_stat(const char *path, os_fstat_t *filestats)
int32 return_code;
char local_path[OS_MAX_LOCAL_PATH_LEN];

if (filestats == NULL)
{
return OS_INVALID_POINTER;
}
/* Check Parameters */
OS_CHECK_POINTER(filestats);

memset(filestats, 0, sizeof(*filestats));

Expand Down Expand Up @@ -502,10 +493,9 @@ int32 OS_cp(const char *src, const char *dest)
osal_id_t file2;
uint8 copyblock[512];

if (src == NULL || dest == NULL)
{
return OS_INVALID_POINTER;
}
/* Check Parameters */
OS_CHECK_POINTER(src);
OS_CHECK_POINTER(dest);

file1 = OS_OBJECT_ID_UNDEFINED;
file2 = OS_OBJECT_ID_UNDEFINED;
Expand Down Expand Up @@ -595,10 +585,7 @@ int32 OS_FDGetInfo(osal_id_t filedes, OS_file_prop_t *fd_prop)
int32 return_code;

/* Check parameters */
if (fd_prop == NULL)
{
return (OS_INVALID_POINTER);
}
OS_CHECK_POINTER(fd_prop);

memset(fd_prop, 0, sizeof(OS_file_prop_t));

Expand Down Expand Up @@ -633,10 +620,7 @@ int32 OS_FileOpenCheck(const char *Filename)
OS_object_iter_t iter;
OS_stream_internal_record_t *stream;

if (Filename == NULL)
{
return (OS_INVALID_POINTER);
}
OS_CHECK_POINTER(Filename);

return_code = OS_ERROR;

Expand Down Expand Up @@ -672,10 +656,7 @@ int32 OS_CloseFileByName(const char *Filename)
OS_object_iter_t iter;
OS_stream_internal_record_t *stream;

if (Filename == NULL)
{
return (OS_INVALID_POINTER);
}
OS_CHECK_POINTER(Filename);

return_code = OS_FS_ERR_PATH_INVALID;

Expand Down
Loading

0 comments on commit 5d22ca6

Please sign in to comment.