Encryption BIOs misbehave when used with non blocking I/O.
authorDr. Stephen Henson <steve@openssl.org>
Thu, 27 Feb 2003 14:07:59 +0000 (14:07 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Thu, 27 Feb 2003 14:07:59 +0000 (14:07 +0000)
Two fixes:

1. If BIO_write() fails inside enc_write() it should return the
   total number of bytes successfully written.

2. If BIO_write() fails during BIO_flush() it should return immediately
   with the error code: previously it would fall through to the final
   encrypt, corrupting the buffer.

crypto/evp/bio_enc.c

index 510e1bc8a4c2f6f1a3578f2d4cbe17c0d5d74f76..ab8185150344057706acd29fefd0185e050793ec 100644 (file)
@@ -271,7 +271,7 @@ static int enc_write(BIO *b, const char *in, int inl)
                        if (i <= 0)
                                {
                                BIO_copy_next_retry(b);
-                               return(i);
+                               return (ret == inl) ? i : ret - inl;
                                }
                        n-=i;
                        ctx->buf_off+=i;
@@ -325,10 +325,7 @@ again:
                        {
                        i=enc_write(b,NULL,0);
                        if (i < 0)
-                               {
-                               ret=i;
-                               break;
-                               }
+                               return i;
                        }
 
                if (!ctx->finished)