Skip to content

Commit ef780a1

Browse files
committed
tcp: Prevent zero length and other invalid reads
1 parent 614126a commit ef780a1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/net/tcp/connection.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ size_t Connection::receive(seq_t seq, const uint8_t* data, size_t n, bool PUSH)
143143

144144
void Connection::write(Chunk buffer)
145145
{
146+
if (UNLIKELY(buffer.size() == 0)) {
147+
throw TCP_error("Can't write zero bytes to TCP stream");
148+
}
149+
146150
// Only write if allowed
147151
if(state_->is_writable())
148152
{
@@ -267,8 +271,11 @@ void Connection::receive_disconnect() {
267271
Expects(read_request and read_request->buffer.buffer());
268272
auto& buf = read_request->buffer;
269273

270-
if(read_request->callback)
271-
read_request->callback(buf.buffer(), buf.size());
274+
if(read_request->callback) {
275+
// TODO: consider adding back when SACK is complete
276+
//if (buf.size() > 0 && buf.missing() == 0)
277+
// read_request->callback(buf.buffer(), buf.size());
278+
}
272279
}
273280

274281
void Connection::segment_arrived(Packet_ptr incoming)

0 commit comments

Comments
 (0)