Skip to content

Commit

Permalink
Avoid buffer overflow in fillBufBuilderOne (bump version)
Browse files Browse the repository at this point in the history
  • Loading branch information
FinleyMcIlwaine committed Jun 21, 2024
1 parent 0fb3574 commit c369749
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.2

* Avoid buffer overflow in fillBufBuilderOne
[#3](https://github.com/kazu-yamamoto/http-semantics/pull/4)

## 0.1.1

* Avoid buffer overflow in runStreamingBuilder
Expand Down
16 changes: 10 additions & 6 deletions Network/HTTP/Semantics/FillBuf.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ fillStreamBodyGetNext takeQ = loop 0

----------------------------------------------------------------

fillBufBuilderOne :: B.BufferWriter -> DynaNext
fillBufBuilderOne writer buf0 room = do
(len, signal) <- writer buf0 room
return $ nextForBuilder len signal
fillBufBuilderOne :: Int -> B.BufferWriter -> DynaNext
fillBufBuilderOne minReq writer buf0 room = do
if room >= minReq
then do
(len, signal) <- writer buf0 room
return $ nextForBuilder len signal
else do
return $ Next 0 True (Just $ fillBufBuilderOne minReq writer)

fillBufBuilderTwo :: ByteString -> B.BufferWriter -> DynaNext
fillBufBuilderTwo bs writer buf0 room
Expand All @@ -104,8 +108,8 @@ fillBufBuilderTwo bs writer buf0 room
nextForBuilder :: BytesFilled -> B.Next -> Next
nextForBuilder len B.Done =
Next len True Nothing -- let's flush
nextForBuilder len (B.More _ writer) =
Next len False $ Just (fillBufBuilderOne writer)
nextForBuilder len (B.More minReq writer) =
Next len False $ Just (fillBufBuilderOne minReq writer)
nextForBuilder len (B.Chunk bs writer) =
Next len False $ Just (fillBufBuilderTwo bs writer)

Expand Down
2 changes: 1 addition & 1 deletion http-semantics.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: >=1.10
name: http-semantics
version: 0.1.1
version: 0.1.2
license: BSD3
license-file: LICENSE
maintainer: Kazu Yamamoto <kazu@iij.ad.jp>
Expand Down

0 comments on commit c369749

Please sign in to comment.