Re: [PATCH] Removed warnings in nfs_sockaddr2universal()

Steve Dickson <[email protected]>
Newsgroups gmane.linux.nfs
Message-ID <[email protected]>

On 5/28/26 3:19 PM, Steve Dickson wrote:
> in function 'nfs_sockaddr2universal',
>      inlined from 'nsm_xmit_getaddr.constprop' at ../../support/nsm/rpc.c:251:17:
> ../../support/nfs/getport.c:459:24: warning: 'strndup' specified bound 108 exceeds source size 26 [-Wstringop-overread]
>    459 |                 return strndup(sun->sun_path, sizeof(sun->sun_path));
>        |                        ^
> 
> Signed-off-by: Steve Dickson <[email protected]>
Committed... (tag: nfs-utils-2-9-2-rc4)

steved
> ---
> This is a chatgpt solution to remove the warning... untested (yet)
> ---
>   support/nfs/getport.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/support/nfs/getport.c b/support/nfs/getport.c
> index 813f7bf9..608e185b 100644
> --- a/support/nfs/getport.c
> +++ b/support/nfs/getport.c
> @@ -452,11 +452,12 @@ char *nfs_sockaddr2universal(const struct sockaddr *sap)
>   	uint16_t port;
>   	size_t count;
>   	char *result;
> -	int len;
> +	int len = sizeof(struct sockaddr);
>   
>   	switch (sap->sa_family) {
>   	case AF_LOCAL:
> -		return strndup(sun->sun_path, sizeof(sun->sun_path));
> +		size_t path_len = len - offsetof(struct sockaddr_un, sun_path);
> +		return strndup(sun->sun_path, path_len);
>   	case AF_INET:
>   		if (inet_ntop(AF_INET, (const void *)&sin->sin_addr.s_addr,
>   					buf, (socklen_t)sizeof(buf)) == NULL)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.