AP_HAL: Fix TOCTOU in ByteBuffer::peekiovec()

This commit is contained in:
Murilo Belluzzo 2016-07-04 22:31:35 -03:00 committed by Lucas De Marchi
parent 9951b94d40
commit 43d4012884

View File

@ -98,13 +98,15 @@ bool ByteBuffer::advance(uint32_t n)
uint8_t ByteBuffer::peekiovec(ByteBuffer::IoVec iovec[2], uint32_t len) uint8_t ByteBuffer::peekiovec(ByteBuffer::IoVec iovec[2], uint32_t len)
{ {
if (len > available()) { uint32_t n = available();
len = available();
if (len > n) {
len = n;
} }
if (len == 0) { if (len == 0) {
return 0; return 0;
} }
uint32_t n;
auto b = readptr(n); auto b = readptr(n);
if (n > len) { if (n > len) {
n = len; n = len;