7 Commits

Author SHA1 Message Date
Dan McNulty
e3379ed8c9 Fix infinite loop when parsing invalid DAP message.
This commit updates `ContentReader::read` to optionally close the
underlying `Reader` when a message is read that does not terminate
the DAP header immediately following the `Content-Length` header
field.

This fixes an infinite loop when parsing an invalid DAP message. In
particular, the infinite loop occurs when a cross-site HTTP request from
a browser running on the same host as a cppdap server is sent to the
server. As cross-site requests to the localhost can be triggered by
untrusted JavaScript, more validation of the DAP messages is required to
protect cppdap-based servers from malicious requests.

This commit introduces a new enum flag on both `Session` and
`ContentReader` to allow a user to indicate that the underlying `Reader`
should be closed when an invalid DAP message is received. The
server example has been updated to indicate that invalid messages
should result in closure of the underlying `Reader`.
2023-07-05 20:12:05 +01:00
Dan McNulty
93d94a7d85 Update StringBuffer to support partial reads test case.
Per #115, `ContentReader::match` must block until the whole pattern is
read or the underlying `Reader` is closed. The previous commit reverted
the change from #50 to ensure this behavior is still implemented.

This commit re-adds the unit test from #50 with an update to the
behavior of `StringBuffer` to correct implement `Reader` so that
the partial read test case is still covered by the unit tests.
2023-07-05 20:12:05 +01:00
Dan McNulty
8399fbae7f Revert "Fix content reader for partial input"
This reverts commit 77209caf044d58c7d87770b377027a65fe696466.
2023-07-05 20:12:05 +01:00
Puneetha Ramachandra
77209caf04 Fix content reader for partial input
When there is partial message in reader, popping out the
characters lead to parse errors on the subsequent attempt
to parse. To avoid this, the last matched characters'
index is stored during parsing and reset on error.
2020-12-01 18:13:31 +00:00
Ben Clayton
261d62d91e Remove unnecessary virtual inheritance
Looks like a copypasta mistake
2020-06-05 10:53:52 +01:00
Ben Clayton
c9187480d1 Fix short reads in ContentReader::buffer()
The actual length of data read by `dap::Reader::read()` was not being correctly inspected.

Fixed, added test.

Bug identified by @kuafuwang.

Fixes #27
2020-05-27 18:40:48 +01:00
Ben Clayton
2dfd15462f Initial drop of cppdap 2019-11-08 21:58:50 +00:00