Mercurial > nomad
changeset 875:e5b305913b1c
common: enforce max read & write size in fscall_{read,write}
The RPC structures have a size limitation and these checks exist to avoid
silent integer truncation. In the future, we could replace these with
loops to invoke the RPC as many times as is necessary to read/write the
entire requested length.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sun, 18 Dec 2022 09:45:56 -0500 |
parents | 7f967ffda1ac |
children | ea51bd7cb9f5 |
files | src/common/fscall.c |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/common/fscall.c Sun Dec 18 10:00:29 2022 -0500 +++ b/src/common/fscall.c Sun Dec 18 09:45:56 2022 -0500 @@ -381,7 +381,10 @@ struct rpc_read_res read_res; int ret; - /* TODO: check for length being too much? */ + STATIC_ASSERT(sizeof(read_req.length) == sizeof(uint32_t)); + + if (len > UINT32_MAX) + return NERR_E2BIG; read_req.handle = handle; read_req.offset = off; @@ -409,7 +412,10 @@ { struct rpc_write_req write_req; - /* TODO: check for length being too much? */ + STATIC_ASSERT(sizeof(write_req.data.data_len) == sizeof(uint32_t)); + + if (len > UINT32_MAX) + return NERR_E2BIG; write_req.handle = handle; write_req.offset = off;