Replace select with poll. 16/213116/1
authorSOURAV BHUWALKA <s-bhuwalka@samsung.com>
Thu, 22 Aug 2019 08:07:31 +0000 (13:37 +0530)
committerSudipto Bal <sudipto.bal@samsung.com>
Fri, 30 Aug 2019 09:49:17 +0000 (09:49 +0000)
commit9b250c87a54d4697440d638f8de12f2ac3413f15
treeab79ba1547013a215f56871f1233343635898a89
parent48221cb16b54e992ed268df82cff3e65f246e1cd
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