Re: [PATCH] net: sunrpc: sizeof('\0') is 4, not 1

From: NeilBrown
Date: Fri Dec 15 2023 - 23:27:53 EST


On Sat, 16 Dec 2023, Ahelenia Ziemiańska wrote:
> To make it self-documenting, the referenced commit added the space
> for the null terminator as sizeof('\0'). The message elaborates on
> why only one byte is needed, so this is clearly a mistake.
> Spell it as 1 /* NUL */ instead.
>
> This is the only result for git grep "sizeof.'" in the tree.
>
> Fixes: commit 1e360a60b24a ("SUNRPC: Address buffer overrun in
> rpc_uaddr2sockaddr()")

It isn't clear to me that "Fixes" is appropriate as that patch isn't
harmful, just confused and sub-optimal.
But it probably doesn't mattter.

Reviewed-by: NeilBrown <neilb@xxxxxxx>

Thanks,
NeilBrown



> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@xxxxxxxxxxxxxxxxxx>
> ---
> net/sunrpc/addr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
> index d435bffc6199..c4ba342f6866 100644
> --- a/net/sunrpc/addr.c
> +++ b/net/sunrpc/addr.c
> @@ -311,7 +311,7 @@ size_t rpc_uaddr2sockaddr(struct net *net, const char *uaddr,
> const size_t uaddr_len, struct sockaddr *sap,
> const size_t salen)
> {
> - char *c, buf[RPCBIND_MAXUADDRLEN + sizeof('\0')];
> + char *c, buf[RPCBIND_MAXUADDRLEN + 1 /* NUL */];
> u8 portlo, porthi;
> unsigned short port;
>
>
> base-commit: 26aff849438cebcd05f1a647390c4aa700d5c0f1
> --
> 2.39.2
>