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 <alexandre.teixeira@etu.emse.fr>
This commit is contained in:
MrFantOlas 2025-07-18 23:20:17 +02:00 committed by GitHub
parent 4adf658907
commit ae3cc48f22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,11 +71,19 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> 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;
}