Replace select with poll. 14/213114/1
authorSOURAV BHUWALKA <s-bhuwalka@samsung.com>
Thu, 22 Aug 2019 08:07:31 +0000 (13:37 +0530)
committerSudipto <sudipto.bal@samsung.com>
Fri, 30 Aug 2019 09:42:07 +0000 (15:12 +0530)
commit8d7febc47ca89a1800ab6266b546939fb86edc14
treedc9fd7011f3e7a5e6642d5c666d735b46d32f42d
parent4c0519a46adbe47ef237de579f405b3be6b769a4
Replace select with poll.

1. select has a limitation of 1024 file descriptors to be monitored.
2. Calling select() or FD_* macros with invalid file descriptor could
result in stack corruption.
3. Currently we don't validate the file descriptors which are passed to it.
Even if we add logic to validate, we cannot recreate the underlying socket
with file descriptor lesser than 1024.

Stack corruption:-
fd_set is an array of bits, of FD_SETSIZE elements.
A variable of fd_set is created in the stack segment.
FD_SET macro apparently doesn’t know about the FD_SETSIZE value,
so even if you pass a FD greater than 1024,
it will actually set to “1” the corresponding bit in the fd_set array of bits,
which actually is OUTSIDE the array. Thus, corrupting the stack.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/560/commits/842a27d1c6be3397687d7788d113f872308de2bc
(cherry-picked from 842a27d1c6be3397687d7788d113f872308de2bc)

Reference:
https://sigquit.wordpress.com/2009/12/24/stack-corruption-improper-use-of-fd_set/

Signed-off-by: Senthil Kumar G S <senthil.gs@samsung.com>
Change-Id: Ie8f7e0b90c9a458ee82f247132c45ff82f2a37ae
Co-authored-by: Senthil Kumar G S <senthil.gs@samsung.com>
Signed-off-by: Sudipto <sudipto.bal@samsung.com>
resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c