net: socket: mgmt: Check buf size in recvfrom()

Return EMSGSIZE if trying to copy too much data into
user supplied buffer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2023-10-10 13:40:08 +03:00 committed by Johan Hedberg
parent 2f79f5e992
commit 0a16d5c7c3

View file

@ -209,8 +209,12 @@ again:
if (info) {
ret = info_len + sizeof(hdr);
ret = MIN(max_len, ret);
memcpy(&copy_to[sizeof(hdr)], info, ret);
if (ret > max_len) {
errno = EMSGSIZE;
return -1;
}
memcpy(&copy_to[sizeof(hdr)], info, info_len);
} else {
ret = 0;
}