1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

Merge pull request #9089 from jflyper/bfdev-serial-blackbox-handle-buffer-overflow-properly

Serial blackbox: check TX buffer space before calling serialWrite
This commit is contained in:
Michael Keller 2019-10-27 15:29:51 +13:00 committed by GitHub
commit 0fd4dec942
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,15 +127,23 @@ void blackboxWrite(uint8_t value)
#endif
case BLACKBOX_DEVICE_SERIAL:
default:
{
int txBytesFree = serialTxBytesFree(blackboxPort);
#ifdef DEBUG_BB_OUTPUT
bbBits += 2;
if (serialTxBytesFree(blackboxPort) == 0) {
++bbDrops;
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 2, bbDrops);
return;
}
bbBits += 2;
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 3, txBytesFree);
#endif
serialWrite(blackboxPort, value);
if (txBytesFree == 0) {
#ifdef DEBUG_BB_OUTPUT
++bbDrops;
DEBUG_SET(DEBUG_BLACKBOX_OUTPUT, 2, bbDrops);
#endif
return;
}
serialWrite(blackboxPort, value);
}
break;
}
@ -181,7 +189,7 @@ int blackboxWriteString(const char *s)
default:
pos = (uint8_t*) s;
while (*pos) {
serialWrite(blackboxPort, *pos);
blackboxWrite(*pos);
pos++;
}