Skip to content

Commit

Permalink
Fix #648, sanitize array refs on impl layer
Browse files Browse the repository at this point in the history
Pass token objects to impl layers to identify the object to operate
on, rather than the index.  The token has extra information including
the original/actual object ID - which matters if the ID might change
as part of the operation (e.g. new/delete).
  • Loading branch information
jphickey committed Dec 4, 2020
1 parent f9d508d commit ffb098d
Show file tree
Hide file tree
Showing 112 changed files with 1,727 additions and 1,117 deletions.
24 changes: 14 additions & 10 deletions src/os/portable/os-impl-bsd-select.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <osapi.h>
#include "os-impl-select.h"
#include "os-shared-select.h"
#include "os-shared-idmap.h"

/****************************************************************************************
DEFINES
Expand Down Expand Up @@ -249,17 +250,20 @@ static int32 OS_DoSelect(int maxfd, fd_set *rd_set, fd_set *wr_set, int32 msecs)
* See prototype for argument/return detail
*
*-----------------------------------------------------------------*/
int32 OS_SelectSingle_Impl(osal_index_t stream_id, uint32 *SelectFlags, int32 msecs)
int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags, int32 msecs)
{
int32 return_code;
fd_set wr_set;
fd_set rd_set;
int32 return_code;
fd_set wr_set;
fd_set rd_set;
OS_impl_file_internal_record_t *impl;

impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token);

/*
* If called on a stream_id which does not support this
* operation, return immediately and do not invoke the system call
*/
if (!OS_impl_filehandle_table[stream_id].selectable)
if (!impl->selectable)
{
return OS_ERR_OPERATION_NOT_SUPPORTED;
}
Expand All @@ -270,22 +274,22 @@ int32 OS_SelectSingle_Impl(osal_index_t stream_id, uint32 *SelectFlags, int32 ms
FD_ZERO(&rd_set);
if (*SelectFlags & OS_STREAM_STATE_READABLE)
{
FD_SET(OS_impl_filehandle_table[stream_id].fd, &rd_set);
FD_SET(impl->fd, &rd_set);
}
if (*SelectFlags & OS_STREAM_STATE_WRITABLE)
{
FD_SET(OS_impl_filehandle_table[stream_id].fd, &wr_set);
FD_SET(impl->fd, &wr_set);
}

return_code = OS_DoSelect(OS_impl_filehandle_table[stream_id].fd, &rd_set, &wr_set, msecs);
return_code = OS_DoSelect(impl->fd, &rd_set, &wr_set, msecs);

if (return_code == OS_SUCCESS)
{
if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &rd_set))
if (!FD_ISSET(impl->fd, &rd_set))
{
*SelectFlags &= ~OS_STREAM_STATE_READABLE;
}
if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &wr_set))
if (!FD_ISSET(impl->fd, &wr_set))
{
*SelectFlags &= ~OS_STREAM_STATE_WRITABLE;
}
Expand Down
Loading

0 comments on commit ffb098d

Please sign in to comment.