mirror of https://github.com/schoebel/mars
net: safeguard recv of bad string size
This commit is contained in:
parent
26bab9b43d
commit
530a938a62
|
@ -984,11 +984,20 @@ int _desc_recv_item(struct mars_socket *msock, void *data, const struct mars_des
|
||||||
status = mars_recv_raw(msock, &len, sizeof(len), sizeof(len));
|
status = mars_recv_raw(msock, &len, sizeof(len), sizeof(len));
|
||||||
if (unlikely(status < 0))
|
if (unlikely(status < 0))
|
||||||
goto done;
|
goto done;
|
||||||
|
if (unlikely(len < 0 || len > KMALLOC_MAX_SIZE)) {
|
||||||
|
MARS_ERR("#%d bad string alloc size %d\n",
|
||||||
|
msock->s_debug_nr, len);
|
||||||
|
status = -EOVERFLOW;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (len > 0 && item) {
|
if (len > 0 && item) {
|
||||||
char *str = _brick_string_alloc(len, line);
|
char *str = _brick_string_alloc(len, line);
|
||||||
|
|
||||||
if (unlikely(!str)) {
|
if (unlikely(!str)) {
|
||||||
MARS_ERR("#%d string alloc error\n", msock->s_debug_nr);
|
MARS_ERR("#%d string alloc error\n",
|
||||||
|
msock->s_debug_nr);
|
||||||
|
status = -ENOMEM;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
*(void**)item = str;
|
*(void**)item = str;
|
||||||
|
|
Loading…
Reference in New Issue