According to your truss output, neither version should work at all; select is
returning 0 in every case which means that no descriptors are ready. Perhaps
AIX's /dev/urandom device driver doesn't support select() functionality. That
would certainly be stupid, but not unheard of.

Your patch introduces a bug - since you only told select to check 1
descriptor, and descriptor number 1 isn't actually set in the fdset, the
select simply times out. This is what the return value 0 means from select.
The if/else clause in this function (hell, the whole loop) is written badly
and doesn't distinguish a timeout from an actual failure. In your case, it
treats the timeout as success and proceeds to read from the descriptor, even
though it should actually skip the read.

I really don't see what the point of using select() here is in the first
place. The fd has already been set to Non-Blocking; either the driver will
honor it or it won't. There's nothing more you can do. If you read from
/dev/urandom and don't get the number of bytes you wanted, you're screwed
anyway.

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc
  Symas: Premier OpenSource Development and Support

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
[EMAIL PROTECTED] via RT

> Hi!
>
> > No patch should be required, not even AIX can be that weird.  An
> > official specification for select() is available at
> >
> http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/libs/c
> ommtrf1/select.htm
>
>
> Ok, is it maybe a PEBKAC. But I cannot find an explanation for the
> following behavior:
>
> I use the little programm that Anders Liljegren mailed at
> http://www.mail-archive.com/[EMAIL PROTECTED]/msg30771
> .html about 2
> weeks ago.
>
> #include <string.h>
> #include <stdlib.h>
> #include <openssl/rand.h>
>
> int main(void)
> {
>     exit(RAND_status());
> }
>
>
>
> Both times openssl is configured with ./Configure  aix43-gcc
> and compiled
> with gcc-3.2.1
> and the IBM linker. The first test is without the patch, the
> second with
> the patch.
>
> Any ideas?
>
>       Andreas Walter
>
>
> truss ./ssl-test
> execve("./ssl-test", 0x2FF22BA4, 0x2FF22BAC)     argc: 1
> __loadx(0x0A040000, 0xD03399AC, 0x00000003, 0x10000000, 0x20000D1D) =
> 0x00000000
> _getpid()                                       = 22600
> _getpid()                                       = 22600
> open("/dev/urandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 3
> _select(4, 0x2FF20A50, 0x00000000, 0x00000000, 0x2FF22A58) = 0
> close(3)                                        = 0
> open("/dev/random", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 3
> _select(4, 0x2FF20A50, 0x00000000, 0x00000000, 0x2FF22A58) = 0
> close(3)                                        = 0
> open("/dev/srandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) Err#2  ENOENT
> socket(1, 1, 0)                                 = 3
> connext(3, 0x2FF20850, 19)                      Err#2  ENOENT
> close(3)                                        = 0
> socket(1, 1, 0)                                 = 3
> connext(3, 0x2FF20850, 15)                      Err#2  ENOENT
> close(3)                                        = 0
> socket(1, 1, 0)                                 = 3
> connext(3, 0x2FF20850, 15)                      Err#2  ENOENT
> close(3)                                        = 0
> socket(1, 1, 0)                                 = 3
> connext(3, 0x2FF20850, 14)                      Err#2  ENOENT
> close(3)                                        = 0
> _getpid()                                       = 22600
> sbrk(0x00000000)                                = 0x2000B4A8
> sbrk(0x00000008)                                = 0x2000B4A8
> sbrk(0x00010010)                                = 0x2000B4B0
> getuidx(2)                                      = 0
> _getpid()                                       = 22600
> _getpid()                                       = 22600
> kfcntl(1, F_GETFL, 0x20008F54)                  = 2
> kfcntl(2, F_GETFL, 0x00000000)                  = 2
> _exit(0)
>
>
>
> truss ./ssl-test-aixpatch
> execve("./ssl-test-aixpatch", 0x2FF22B9C, 0x2FF22BA4)  argc: 1
> __loadx(0x0A040000, 0xD03399AC, 0x00000003, 0x10000000, 0x20000D35) =
> 0x00000000
> _getpid()                                       = 24072
> _getpid()                                       = 24072
> open("/dev/urandom", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 3
> _select(1, 0x2FF20A40, 0x00000000, 0x00000000, 0x2FF22A48) = 0
> kread(3, " @ Z ??- G ?806 W V '".., 32)      = 32
> close(3)                                        = 0
> _getpid()                                       = 24072
> sbrk(0x00000000)                                = 0x2000B4D4
> sbrk(0x0000000C)                                = 0x2000B4D4
> sbrk(0x00010010)                                = 0x2000B4E0
> _getpid()                                       = 24072
> getuidx(2)                                      = 0
> _getpid()                                       = 24072
> _getpid()                                       = 24072
> kfcntl(1, F_GETFL, 0x20008F6C)                  = 67110914
> kfcntl(2, F_GETFL, 0x00000000)                  = 67110914
> _exit(1)
>
>
>
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> Development Mailing List                       [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]
>

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to