From 73036eb7e47badf393f566778fb934856c7af26b Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Mon, 12 Feb 2024 17:05:52 +0000 Subject: IVGCVSW-8284 Out of bounds access error in BasePipeServer.cpp Change-Id: I52c97f003cc8b26aae7e1f5037c79f0d05bd7143 Signed-off-by: Colm Donelan --- profiling/server/src/basePipeServer/BasePipeServer.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/profiling/server/src/basePipeServer/BasePipeServer.cpp b/profiling/server/src/basePipeServer/BasePipeServer.cpp index 96e8e24a2c..08d9126fb9 100644 --- a/profiling/server/src/basePipeServer/BasePipeServer.cpp +++ b/profiling/server/src/basePipeServer/BasePipeServer.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2020, 2024 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace arm { @@ -87,8 +87,15 @@ bool BasePipeServer::WaitForStreamMetaData() uint32_t metaDataLength = ToUint32(&header[4], m_Endianness) - 4; // Read the entire packet. std::vector packetData(metaDataLength); - if (metaDataLength != - arm::pipe::numeric_cast(arm::pipe::Read(m_ClientConnection, packetData.data(), metaDataLength))) + long bytesRead = arm::pipe::Read(m_ClientConnection, packetData.data(), metaDataLength); + // On Socket error Read will return -1. + if (bytesRead < 0) + { + std::cerr << ": Socket error: " << strerror(errno) << std::endl; + return false; + } + // bytesRead cannot be negative here. + if (metaDataLength != arm::pipe::numeric_cast(bytesRead)) { std::cerr << ": Protocol read error. Data length mismatch." << std::endl; return false; -- cgit v1.2.1