From ae3cc48f223386b057137400354ed0ca1f7a8b1a Mon Sep 17 00:00:00 2001 From: MrFantOlas <57408212+MrFantOlas@users.noreply.github.com> Date: Fri, 18 Jul 2025 23:20:17 +0200 Subject: [PATCH] protocols/gamma: support pipes (#11076) Add support for pipes and potentially other valid file descriptors. Add check for more data on the socket than the required amount as per protocol. --------- Co-authored-by: Alexandre Teixeira --- src/protocols/GammaControl.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/protocols/GammaControl.cpp b/src/protocols/GammaControl.cpp index 29a9cae4..e371496d 100644 --- a/src/protocols/GammaControl.cpp +++ b/src/protocols/GammaControl.cpp @@ -71,11 +71,19 @@ CGammaControl::CGammaControl(SP resource_, wl_resource* out return; } - ssize_t readBytes = pread(gammaFd.get(), m_gammaTable.data(), m_gammaTable.size() * sizeof(uint16_t), 0); - if (readBytes < 0 || (size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t)) { + ssize_t readBytes = read(gammaFd.get(), m_gammaTable.data(), m_gammaTable.size() * sizeof(uint16_t)); + + ssize_t moreBytes = 0; + { + const size_t BUF_SIZE = 1; + char buf[BUF_SIZE] = {}; + moreBytes = read(gammaFd.get(), buf, BUF_SIZE); + } + + if (readBytes < 0 || (size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t) || moreBytes != 0) { LOGM(ERR, "Failed to read bytes"); - if ((size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t)) { + if ((size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t) || moreBytes > 0) { gamma->error(ZWLR_GAMMA_CONTROL_V1_ERROR_INVALID_GAMMA, "Gamma ramps size mismatch"); return; }