rtp-sap: handle uninitialized avail

When the ioctl fails, avail might be uninitialized. Check the ioctl
return value and handle invalid avail.
This commit is contained in:
Wim Taymans 2026-05-06 11:29:20 +02:00
parent c4a2f9b480
commit d32a21c4ee

View file

@ -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);