From c8f6fe7641b1ba3d74b0df58c1de3644b2f7bf11 Mon Sep 17 00:00:00 2001 From: Andrey Bychkov Date: Mon, 10 Aug 2026 21:39:31 +0300 Subject: [PATCH] =?UTF-8?q?Reapply=20"fix:=20PISingleApplication=20TOCTOU?= =?UTF-8?q?=20=E2=80=94=20two=20shm=20reads=20replaced=20with=20single=20a?= =?UTF-8?q?tomic=20read"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fc2e49b0966568b5abb0766c0b100de163dd1359. --- libs/main/application/pisingleapplication.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/main/application/pisingleapplication.cpp b/libs/main/application/pisingleapplication.cpp index 46e342e3..217a1ba7 100644 --- a/libs/main/application/pisingleapplication.cpp +++ b/libs/main/application/pisingleapplication.cpp @@ -128,12 +128,14 @@ void PISingleApplication::run() { int st_[2] = {sacnt, sacnt}; shm->write(st_, 8); // piCoutObj << "write" << sacnt; - int ri[3] = {0, 0, 0}; const int hdr_sz = sizeof(int) * 3; - shm->read(ri, hdr_sz); + PIByteArray all(shm->size()); + shm->read(all.data(), all.size()); + int ri[3] = {0, 0, 0}; + memcpy(ri, all.data(), hdr_sz); if (ri[2] != 0 && ri[0] == ri[1]) { - readed.resize(shm->size() - hdr_sz); - shm->read(readed.data(), readed.size(), hdr_sz); + readed.resize(all.size() - hdr_sz); + memcpy(readed.data(), all.data() + hdr_sz, readed.size()); PIByteArray msg; readed >> msg; if (msg.isNotEmpty()) {