Windows SDP scanner: properly check remainingLength
The remainingLength variable represents the expected amount of bytes
in the SDP sequence entry.
Its value is reduced each time we read N bytes from the buffer. However,
the code never verified if remainingLength is actually large enough to
fit the number of bytes to be read.
In case of a malicious packet, the length value could be less than the
actual number of bytes, in which case subtracting will underflow over
UINT8_MAX.
Since the remainingLength value is used as a guard to exit the infinite
loop, in such case we might get stuck in this loop forever, because the
value will never be strictly equal to zero.
This patch adds checks that the number of bytes to be read actually fits
into the remainingLength. If it does not, the sequence is corrupted, so
we just return early.
The code introduces a local RETURN_IF_INVALID_LENGTH macro to avoid
repeating the same lines over and over again.
This issue can be triggered with an external malicious or corrupted
SDP record, so picking all the way back to 5.15.
Task-number: QTBUG-145934
Pick-to: 6.11 6.8 6.5 5.15
Change-Id: I46c1824cd1103a28159a6b763685e2ae519f0e64
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>