Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #390, OS_SelectFd... API's check that Set != NULL #391

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 53 additions & 21 deletions src/os/shared/osapi-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs)
uint32 local_id;
OS_common_record_t *record;

return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &local_id, &record);
if (return_code == OS_SUCCESS)
if(StateFlags == NULL)
{
return_code = OS_SelectSingle_Impl(local_id, StateFlags, msecs);
OS_ObjectIdRefcountDecr(record);
return_code = OS_INVALID_POINTER;
}
else
{
return_code = OS_ObjectIdGetById(OS_LOCK_MODE_REFCOUNT, OS_OBJECT_TYPE_OS_STREAM, objid, &local_id, &record);
if (return_code == OS_SUCCESS)
{
return_code = OS_SelectSingle_Impl(local_id, StateFlags, msecs);
OS_ObjectIdRefcountDecr(record);
}
}

return return_code;
Expand Down Expand Up @@ -102,8 +109,16 @@ int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs)
*-----------------------------------------------------------------*/
int32 OS_SelectFdZero(OS_FdSet *Set)
{
memset(Set,0,sizeof(OS_FdSet));
return OS_SUCCESS;
int32 return_code = OS_SUCCESS;
if (Set == NULL)
{
return_code = OS_INVALID_POINTER;
}
else
{
memset(Set,0,sizeof(OS_FdSet));
}
return return_code;
} /* end OS_SelectFdZero */

/*----------------------------------------------------------------
Expand All @@ -116,13 +131,20 @@ int32 OS_SelectFdZero(OS_FdSet *Set)
*-----------------------------------------------------------------*/
int32 OS_SelectFdAdd(OS_FdSet *Set, uint32 objid)
{
int32 return_code;
int32 return_code = OS_SUCCESS;
uint32 local_id;

return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);
if (return_code == OS_SUCCESS)
if (Set == NULL)
{
Set->object_ids[local_id >> 3] |= 1 << (local_id & 0x7);
return_code = OS_INVALID_POINTER;
}
else
{
return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);
if (return_code == OS_SUCCESS)
{
Set->object_ids[local_id >> 3] |= 1 << (local_id & 0x7);
}
}

return return_code;
Expand All @@ -138,13 +160,20 @@ int32 OS_SelectFdAdd(OS_FdSet *Set, uint32 objid)
*-----------------------------------------------------------------*/
int32 OS_SelectFdClear(OS_FdSet *Set, uint32 objid)
{
int32 return_code;
int32 return_code = OS_SUCCESS;
uint32 local_id;

return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);
if (return_code == OS_SUCCESS)
if (Set == NULL)
{
return_code = OS_INVALID_POINTER;
}
else
{
Set->object_ids[local_id >> 3] &= ~(1 << (local_id & 0x7));
return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);
if (return_code == OS_SUCCESS)
{
Set->object_ids[local_id >> 3] &= ~(1 << (local_id & 0x7));
}
}

return return_code;
Expand All @@ -160,16 +189,19 @@ int32 OS_SelectFdClear(OS_FdSet *Set, uint32 objid)
*-----------------------------------------------------------------*/
bool OS_SelectFdIsSet(OS_FdSet *Set, uint32 objid)
{
int32 return_code;
uint32 local_id;

return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);
if (return_code != OS_SUCCESS)
if (Set != NULL)
{
return false;
uint32 local_id;
int32 return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id);

if (return_code == OS_SUCCESS)
{
return ((Set->object_ids[local_id >> 3] >> (local_id & 0x7)) & 0x1);
}
}

return ((Set->object_ids[local_id >> 3] >> (local_id & 0x7)) & 0x1);
/* error occurred (Set == NULL or ObjjectIdToArrayIndex returned error), return false */
return false;
} /* end OS_SelectFdIsSet */