Skip to content

Commit

Permalink
control: process all available input buffer
Browse files Browse the repository at this point in the history
Process input buffer in a loop until it has all been consumed or we only
have a partial packet.
  • Loading branch information
davmac314 committed Nov 6, 2023
1 parent a52cc06 commit 2bf8bcc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Control protocol versions:
// 1 - dinit 0.16 and prior
// 2 - dinit 0.17 (adds SETTRIGGER, CATLOG, SIGNAL)
// 3 - (unreleased) (adds QUERYSERVICEDSCDIR)
// 3 - dinit 0.17.1 (adds QUERYSERVICEDSCDIR)

// common communication datatypes
using namespace dinit_cptypes;
Expand Down Expand Up @@ -1345,16 +1345,19 @@ bool control_conn_t::data_ready() noexcept
}

// complete packet?
if (rbuf.get_length() >= chklen) {
while (rbuf.get_length() >= chklen) {
try {
return !process_packet();
}
catch (std::bad_alloc &baexc) {
do_oom_close();
return false;
}

chklen = std::max(chklen, 1u);
}
else if (rbuf.get_length() == rbuf.get_size()) {

if (rbuf.get_length() == rbuf.get_size()) {
// Too big packet
log(loglevel_t::WARN, "Received too-large control packet; dropping connection");
bad_conn_close = true;
Expand Down

0 comments on commit 2bf8bcc

Please sign in to comment.