[PATCH 1/1] In socket_recv_thread(), don't try to iov_append() a NULL buffer.

Valerie Aurora val at versity.com
Tue Mar 18 07:48:50 PDT 2025


On Thu, Mar 13, 2025 at 7:52 PM Chris Kirby <ckirby at versity.com> wrote:
>
> Signed-off-by: Chris Kirby <ckirby at versity.com>
> ---
>  shared/mtr-socket.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/shared/mtr-socket.c b/shared/mtr-socket.c
> index 3794c0f..e6d520d 100644
> --- a/shared/mtr-socket.c
> +++ b/shared/mtr-socket.c
> @@ -212,7 +212,10 @@ static void socket_recv_thread(struct thread *thr, void *arg)
>                 }
>
>                 iovcnt = iov_append(iov, 0, page_address(ctl_page), mdesc.ctl_size);
> -               iovcnt = iov_append(iov, iovcnt, page_address(mdesc.data_page), mdesc.data_size);
> +
> +               if (mdesc.data_size) {
> +                       iovcnt = iov_append(iov, iovcnt, page_address(mdesc.data_page), mdesc.data_size);
> +               }
>
>                 ret = whole_iovec(readv, pinf->fd, iov, iovcnt);
>                 if (ret < 0)
> --
> 2.39.5 (Apple Git-154)

Nice catch, thanks for finding this! I was one of the people whose
compiler hid this.

This looks correct as far as my limited understanding goes, so I just
have some tiny style notes:

Since it is only one line inside the if statement, maybe remove the brackets?

I like the commit message but I think it would work better with an
even shorter title and the current title as the body, plus maybe a
note about why it might not show up for some people:

Fix null deference in socket_recv_thread()

In socket_recv_thread(), don't try to iov_append() a NULL buffer.
Compiler optimizations hide this bug for some versions of gcc.

Thanks,

Valerie



More information about the ngnfs-devel mailing list