net/local: Return an error when write the too big packet.

Verification:
  Write a packet, the length is bigger than CONFIG_DEV_FIFO_SIZE.
  The return value should be -1, and the errno is EMSGSIZE.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
liqinhui 2023-08-07 17:03:31 +08:00 committed by Xiang Xiao
parent 89174e6a1a
commit 719191ac72
1 changed files with 6 additions and 0 deletions

View File

@ -130,6 +130,12 @@ int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
len16 += iov->iov_len; len16 += iov->iov_len;
} }
if (len16 > CONFIG_DEV_FIFO_SIZE - sizeof(uint16_t))
{
nerr("ERROR: Packet is too big: %d\n", len16);
return -EMSGSIZE;
}
ret = local_fifo_write(filep, (FAR const uint8_t *)&len16, ret = local_fifo_write(filep, (FAR const uint8_t *)&len16,
sizeof(uint16_t)); sizeof(uint16_t));
if (ret != sizeof(uint16_t)) if (ret != sizeof(uint16_t))