From d32a21c4eec4897d04808e5ff0ac2dac46498231 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 6 May 2026 11:29:20 +0200 Subject: [PATCH] rtp-sap: handle uninitialized avail When the ioctl fails, avail might be uninitialized. Check the ioctl return value and handle invalid avail. --- src/modules/module-rtp-sap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/module-rtp-sap.c b/src/modules/module-rtp-sap.c index 290a34b51..97bedfb2a 100644 --- a/src/modules/module-rtp-sap.c +++ b/src/modules/module-rtp-sap.c @@ -591,13 +591,13 @@ static bool update_ts_refclk(struct impl *impl) return false; } - // Read if something is left in the socket - int avail; + int avail = 0; uint8_t tmp; - ioctl(impl->ptp_fd, FIONREAD, &avail); - pw_log_debug("Flushing stale data: %u bytes", avail); - while (avail-- && read(impl->ptp_fd, &tmp, 1)); + if (ioctl(impl->ptp_fd, FIONREAD, &avail) == 0 && avail > 0) { + pw_log_debug("Flushing stale data: %d bytes", avail); + while (avail-- > 0 && read(impl->ptp_fd, &tmp, 1) == 1); + } struct ptp_management_msg req; spa_zero(req);