On Fri, Jul 19, 2002 at 10:39:21AM +0200, Martin Sj�gren via RT wrote:
> tor 2002-07-18 klockan 13.04 skrev Bodo Moeller via RT:
> 
> > SSL_read() and SSL_write() are not really meant to be called with zero
> > length.  The return value cannot be larger than zero when this is
> > done, so SSL_get_error() will interpret the return value as an error
> > indication.
> 
> Then the documentation should say this in large friendly letters :)
>
> > We could change SSL_read() and SSL_write() to return an actual error
> > when they are called with length 0, but this might break programs that
> > do such calls but don't rely on SSL_get_error() for them.  I suppose
> > it should be possible to change the implementations behind SSL_read()
> > and SSL_write() (i.e. ssl3_read() etc.) to use an extra flag for the
> > special case of zero length parameters so that SSL_get_error() will
> > indicate success unless there really was some kind of error, but I'm
> > not convinced this is worth the effort -- why call the functions with
> > length 0 anyway?
> 
> Why? Perhaps because of mistakes in the coding. Perhaps because the
> author didn't think it was invalid and didn't want to add to the
> complexity of his code with Yet Another if. This bug bit us because the
> protocol framework we are using did exactly this and it took us a long
> time tracking it down.
> 
> Note that it's perfectly valid to call write(2) with an empty string and
> that a zero return doesn't mean the connection was closed.

Hmm. Manual pages between systems can be different. I cite from Linux now:
read(2):
...
        On success, the number of bytes  read  is  returned  (zero
        indicates  end of file), and the file position is advanced
        by this number.
...

Therefore the case, that '0' bytes were read actually could not appear.
Translated to the SSL_* case this means, that SSL_read() is behaving
quite similar to that of read(2).

With respect to write(2):
...
        On success, the number of bytes written are returned (zero
        indicates nothing was written).  On error, -1 is returned,
        and  errno is set appropriately.  If count is zero and the
        file descriptor refers  to  a  regular  file,  0  will  be
        returned  without causing any other effect.  For a special
        file, the results are not portable.
...
Thus it seems, that writing an amount of 0 bytes is not that portable as
it seems.
What would be thinkable is that SSL_write() with a bytecount of "0" gets
a shortcut returning "0" bytes written without actually doing anything.
This however might conflict with SSL_get_error() and I do not think, that
it would be a worthwhile addition.

It seems that an appropriate addition to the SSL_write() manual page is
the correct solution.

Best regards,
        Lutz
-- 
Lutz Jaenicke                             [EMAIL PROTECTED]
http://www.aet.TU-Cottbus.DE/personen/jaenicke/
BTU Cottbus, Allgemeine Elektrotechnik
Universitaetsplatz 3-4, D-03044 Cottbus

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

Reply via email to