From b346a8e2787bac4eea8dda7320491f82771bef69 Mon Sep 17 00:00:00 2001 From: Timo Wischer Date: Wed, 24 Oct 2018 14:08:28 +0200 Subject: [PATCH] JackRequest: Add end marker and verify them on read Without this marker partly written messages cannot be detected before processing them. Change-Id: I38802e9df2a09d1ad0371aba80fc1523cec2ddfe Signed-off-by: Timo Wischer --- common/JackRequest.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/JackRequest.h b/common/JackRequest.h index f504d800..a7f04bd1 100644 --- a/common/JackRequest.h +++ b/common/JackRequest.h @@ -94,6 +94,7 @@ struct JackRequest }; static const int StartMarker = 'R' | ('e' << 8) | ('q' << 16) | ('S' << 24); + static const int EndMarker = 'R' | ('e' << 8) | ('q' << 16) | ('E' << 24); static int ReadType(detail::JackChannelTransactionInterface* trans, RequestType& type) { @@ -136,6 +137,8 @@ protected: public: DATA d; protected: + const int fEnd = JackRequest::EndMarker; + template JackRequestMessage(Args&... args) : fType(DATA::Type()), fSize(sizeof(JackRequestMessage) - sizeof(fStart) - sizeof(fType) - sizeof(fSize)), @@ -151,7 +154,16 @@ protected: return -1; } + /* Size also contains fEnd */ CheckRes(trans->Read(&d, fSize)); + if (fEnd != JackRequest::EndMarker) { + jack_error("Request end marker not found (exp %08x act %08x). Request of type %d will be ignored!", + JackRequest::EndMarker, fEnd, fType); + + /* no need to sync here. Will be done by JackRequest::ReadType() */ + return -1; + } + return 0; }