modem: simcom-sim7080: do not send fragmented data as multiple datagrams

Check if there are multiple non-empty data fragments passed to sendmsg()
function. If positive, then set EMSGSIZE errno and return -1, as that case
is not handled properly with current implementation.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
Marcin Niestroj 2022-05-24 12:35:38 +02:00 committed by Marti Bolivar
commit df5d1f220b

View file

@ -447,6 +447,7 @@ exit:
*/
static ssize_t offload_sendmsg(void *obj, const struct msghdr *msg, int flags)
{
struct modem_socket *sock = obj;
ssize_t sent = 0;
const char *buf;
size_t len;
@ -458,6 +459,17 @@ static ssize_t offload_sendmsg(void *obj, const struct msghdr *msg, int flags)
return -EAGAIN;
}
if (sock->type == SOCK_DGRAM) {
/*
* Current implementation only handles single contiguous fragment at a time, so
* prevent sending multiple datagrams.
*/
if (msghdr_non_empty_iov_count(msg) > 1) {
errno = EMSGSIZE;
return -1;
}
}
for (int i = 0; i < msg->msg_iovlen; i++) {
buf = msg->msg_iov[i].iov_base;
len = msg->msg_iov[i].iov_len;