From 315fbba3e186f9c7e64ae2ad1f406a0e8abd95e7 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Sat, 20 Feb 2021 03:17:48 +0000 Subject: [PATCH] crimson/tools/store-nbd: actually check magic Signed-off-by: Samuel Just --- src/crimson/tools/store-nbd.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/crimson/tools/store-nbd.cc b/src/crimson/tools/store-nbd.cc index ddaae6e6506..fc0975b153f 100644 --- a/src/crimson/tools/store-nbd.cc +++ b/src/crimson/tools/store-nbd.cc @@ -153,8 +153,14 @@ struct request_context_t { } bool check_magic() const { - // todo - return true; + auto ret = magic == NBD_REQUEST_MAGIC; + if (!ret) { + logger().error( + "Invalid magic {} should be {}", + magic, + NBD_REQUEST_MAGIC); + } + return ret; } uint32_t get_command() const { @@ -184,6 +190,12 @@ struct request_context_t { "Got request, magic {}, type {}, from {}, len {}", magic, type, from, len); + if (!check_magic()) { + throw std::system_error( + std::make_error_code( + std::errc::invalid_argument)); + } + if (has_input_buffer()) { return in.read_exactly(len).then([this](auto buf) { in_buffer = ceph::buffer::create_page_aligned(len); -- 2.39.5