Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

It causes an undefined behaviour to call SSL_write() with an empty bu…

…ffer, according to the OpenSSL docs
  • Loading branch information...
commit 4645ab49af3292c2e222273ba9b502f1b4f7aaaf 1 parent bf0f7de
PHO phonohawk authored

Showing 1 changed file with 9 additions and 7 deletions. Show diff stats Hide diff stats

  1. +9 7 OpenSSL/Session.hsc
16 OpenSSL/Session.hsc
@@ -451,13 +451,15 @@ write ssl bs = sslBlock (`tryWrite` bs) ssl >> return ()
451 451 -- | Try to write a given ByteString to the SSL connection without blocking.
452 452 tryWrite :: SSL -> B.ByteString -> IO (SSLResult ())
453 453 tryWrite ssl bs
454   - = B.unsafeUseAsCStringLen bs $ \(ptr, len) ->
455   - do result <- sslIOInner "SSL_write" _ssl_write ptr len ssl
456   - case result of
457   - SSLDone 0 -> ioError $ errnoToIOError "SSL_write" ePIPE Nothing Nothing
458   - SSLDone _ -> return $ SSLDone ()
459   - WantRead -> return WantRead
460   - WantWrite -> return WantWrite
  454 + | B.null bs = return $ SSLDone ()
  455 + | otherwise
  456 + = B.unsafeUseAsCStringLen bs $ \(ptr, len) ->
  457 + do result <- sslIOInner "SSL_write" _ssl_write ptr len ssl
  458 + case result of
  459 + SSLDone 0 -> ioError $ errnoToIOError "SSL_write" ePIPE Nothing Nothing
  460 + SSLDone _ -> return $ SSLDone ()
  461 + WantRead -> return WantRead
  462 + WantWrite -> return WantWrite
461 463
462 464 -- | Lazily read all data until reaching EOF. If the connection dies
463 465 -- without a graceful SSL shutdown, an exception is raised.

0 comments on commit 4645ab4

Please sign in to comment.
Something went wrong with that request. Please try again.