]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/tools/store-nbd: check length of buffer
authorSamuel Just <sjust@redhat.com>
Sat, 20 Feb 2021 03:27:49 +0000 (03:27 +0000)
committerSamuel Just <sjust@redhat.com>
Sat, 20 Feb 2021 03:28:12 +0000 (03:28 +0000)
read_exactly does not return an error if the stream
has ended.

Signed-off-by: Samuel Just <sjust@redhat.com>
src/crimson/tools/store-nbd.cc

index 839daff8dc6607581ea24edd3a2c2ac0a5d2bb3f..ddaae6e65068ebc84a59f873c52c5a3180c747a6 100644 (file)
@@ -168,6 +168,11 @@ struct request_context_t {
   seastar::future<> read_request(seastar::input_stream<char> &in) {
     return in.read_exactly(sizeof(struct nbd_request)
     ).then([this, &in](auto buf) {
+      if (buf.size() < sizeof(struct nbd_request)) {
+       throw std::system_error(
+         std::make_error_code(
+           std::errc::connection_reset));
+      }
       auto p = buf.get();
       magic = seastar::consume_be<uint32_t>(p);
       type = seastar::consume_be<uint32_t>(p);