NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: select() timeout



On 2012-02-27 09:23, Matthias Scheler wrote:
On Sun, Feb 19, 2012 at 07:33:53PM -0500, James K. Lowden wrote:
Matthias Scheler<tron%zhadum.org.uk@localhost>  wrote:

And select(2) is a dangerous API.

Dangerous how?  When the filehandle count is controlled,

It is not the number of file descriptors that matter but the highest
file descriptor number.

... what problem does it present?

I've see select(2) blanking a huge portion of stack space under Linux
because OpenSSL got a file descriptor number outside of FD_SETSIZE.
The author of this bit of code had just like you assumed that nothing
could go wrong when you use select(2) to handle a single file descriptor.

Newer version of OpenSSL use poll(2).

Any code that use values without checking ranges or results is always dangerous. This is not proof that select() is dangerous (or more dangerous than any other system call).

Did OpenSSL in fact mess up because calling select() that messed the stack up? As you say "blanking out", I would have guessed that is would be FD_ZERO in fact.

select() should work on set sizes larger than FD_SETSIZE without a problem, as far as I can tell. But you, as the called, must make sure that you call select() with sane parameters. It won't do to call select() with a very high upper limit on file descriptors, but only provide a small fd_set. But I fail to see that this makes select() any more dangerous than any other system call. read() can clobber all your memory if you pass bad parameters in to it, for example... :-)

        Johnny

--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index