mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 18:24:13 +01:00
Ensure we never write zero bytes (#4284)
This commit is contained in:
parent
351ea04517
commit
ed4a7210d3
1 changed files with 6 additions and 0 deletions
|
@ -616,6 +616,9 @@ APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, size_t len) {
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
iov[0].iov_base = header;
|
iov[0].iov_base = header;
|
||||||
iov[0].iov_len = 3;
|
iov[0].iov_len = 3;
|
||||||
|
if (len == 0) {
|
||||||
|
return write_raw_(iov, 1);
|
||||||
|
}
|
||||||
iov[1].iov_base = const_cast<uint8_t *>(data);
|
iov[1].iov_base = const_cast<uint8_t *>(data);
|
||||||
iov[1].iov_len = len;
|
iov[1].iov_len = len;
|
||||||
|
|
||||||
|
@ -913,6 +916,9 @@ APIError APIPlaintextFrameHelper::write_packet(uint16_t type, const uint8_t *pay
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
iov[0].iov_base = &header[0];
|
iov[0].iov_base = &header[0];
|
||||||
iov[0].iov_len = header.size();
|
iov[0].iov_len = header.size();
|
||||||
|
if (payload_len == 0) {
|
||||||
|
return write_raw_(iov, 1);
|
||||||
|
}
|
||||||
iov[1].iov_base = const_cast<uint8_t *>(payload);
|
iov[1].iov_base = const_cast<uint8_t *>(payload);
|
||||||
iov[1].iov_len = payload_len;
|
iov[1].iov_len = payload_len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue