50: Fix TCP command interface rx buffer wrapping r=jordens a=dnadlinger

Previously, if a message spanned the end of the
receive ring buffer, the last byte in the buffer
would be missing from the to-be-decoded message,
leading to a parse error or panic.

With this commit, >3M commands were exchanged
over one socket without further issues.

Co-authored-by: David Nadlinger <code@klickverbot.at>
This commit is contained in:
bors[bot] 2019-11-13 09:57:02 +00:00 committed by GitHub
commit 4ee902027f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -852,7 +852,7 @@ impl Server {
self.discard = true;
self.data.clear();
} else if !self.discard && len > 0 {
self.data.extend_from_slice(&buf[..len - 1]).unwrap();
self.data.extend_from_slice(&buf[..len]).unwrap();
}
(len, found)
}).unwrap();
@ -862,7 +862,7 @@ impl Server {
json_reply(socket, &Response { code: 520, message: "command buffer overflow" });
self.data.clear();
} else {
let r = from_slice::<T>(&self.data);
let r = from_slice::<T>(&self.data[..self.data.len() - 1]);
self.data.clear();
match r {
Ok(res) => {