Skip to content
Browse files

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

…ffer, according to the OpenSSL docs
  • Loading branch information...
1 parent bf0f7de commit 4645ab49af3292c2e222273ba9b502f1b4f7aaaf @phonohawk phonohawk committed Nov 16, 2011
Showing with 9 additions and 7 deletions.
  1. +9 −7 OpenSSL/Session.hsc
View
16 OpenSSL/Session.hsc
@@ -451,13 +451,15 @@ write ssl bs = sslBlock (`tryWrite` bs) ssl >> return ()
-- | Try to write a given ByteString to the SSL connection without blocking.
tryWrite :: SSL -> B.ByteString -> IO (SSLResult ())
tryWrite ssl bs
- = B.unsafeUseAsCStringLen bs $ \(ptr, len) ->
- do result <- sslIOInner "SSL_write" _ssl_write ptr len ssl
- case result of
- SSLDone 0 -> ioError $ errnoToIOError "SSL_write" ePIPE Nothing Nothing
- SSLDone _ -> return $ SSLDone ()
- WantRead -> return WantRead
- WantWrite -> return WantWrite
+ | B.null bs = return $ SSLDone ()
+ | otherwise
+ = B.unsafeUseAsCStringLen bs $ \(ptr, len) ->
+ do result <- sslIOInner "SSL_write" _ssl_write ptr len ssl
+ case result of
+ SSLDone 0 -> ioError $ errnoToIOError "SSL_write" ePIPE Nothing Nothing
+ SSLDone _ -> return $ SSLDone ()
+ WantRead -> return WantRead
+ WantWrite -> return WantWrite
-- | Lazily read all data until reaching EOF. If the connection dies
-- 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.