Fix FD_SET macro stack smashing error#63
Conversation
|
FD_SET macro is limited by FD_SETSIZE constant defined in platforms. In most systems it is defined as 1024. This patch enables poll(2) which is safer and also POSIX (cross-platform) for the library. |
|
I avoid changing the code and design drastically and tried to respect the design. But this code can be improved even more. |
|
There was a previous merge request several years ago to change the select() to poll() or epoll(). As I recall the reason this wasn't done is that at the time select() was more prevalent in some of the platforms using libcli. My understanding is that poll() is much more common now. |
|
Yeah, that seems fine. I will make another patch with #LIBCLI_USE_POOL guard. |
|
When you do this, please set it up so the default is to keep the current select() call. Let the user define LIBCLI_USE_POLL when building (for example - make -D LIBCLI_USE_POLL) to override the behavior. |
FD_SET macro is considered unsecure, it does not check boundaries and causes segfaults. This fix does use poll(2), which is considered better than select(2). However poll(2) is not enabled by default, LIBCLI_USE_POLL preprocessor definition is required.
|
I edited my commit with requested behavior. It appears Windows is still unable to support poll(2) so it is excluded with define guards. Users can compile with |
|
Concur, was just looking over your patch. I'll likely merge it in shortly. My primary platform is Linux, so I don't have a Windows platform to test with. Will run a few tests also on my side. |
|
I was preparing to merge this and realized I don't have a good attribution for you. Also, I may put an additional check fairly early on in cli_loop() if the 'select' call is used to compare it with FD_SETSIZE and punt with an error message if out of bounds. |
|
Sweet, checking for errors early is a good idea. Using your email would be OK. |
|
Ok, will do under my email, recognizing your github name in the body. Will merge first, then update spec in my branch with attributions. |
FD_SET macro is considered insecure, it does not check boundaries and
causes segfaults.
This fix does use poll(2), which is considered safer than select(2).