diff mbox series

[net,v2] net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr()

Message ID 31b27c8e54f131b7eabcbd78573f0b5bfe380d8c.1698184674.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1362 this patch: 1362
netdev/cc_maintainers success CCed 14 of 14 maintainers
netdev/build_clang success Errors and warnings before: 1386 this patch: 1386
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1386 this patch: 1386
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Christophe JAILLET Oct. 24, 2023, 9:58 p.m. UTC
The intent is to check if the strings' are truncated or not. So, >= should
be used instead of >, because strlcat() and snprintf() return the length of
the output, excluding the trailing NULL.

Fixes: a02d69261134 ("SUNRPC: Provide functions for managing universal addresses")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: Fix cut'n'paste typo in subject
    Add net in [PATCH...]
---
 net/sunrpc/addr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Benjamin Coddington Oct. 25, 2023, 12:35 p.m. UTC | #1
On 24 Oct 2023, at 17:58, Christophe JAILLET wrote:

> The intent is to check if the strings' are truncated or not. So, >= should
> be used instead of >, because strlcat() and snprintf() return the length of
> the output, excluding the trailing NULL.
>
> Fixes: a02d69261134 ("SUNRPC: Provide functions for managing universal addresses")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> v2: Fix cut'n'paste typo in subject
>     Add net in [PATCH...]
> ---

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>

Ben
Chuck Lever III Oct. 25, 2023, 2:30 p.m. UTC | #2
On Tue, Oct 24, 2023 at 11:58:20PM +0200, Christophe JAILLET wrote:
> The intent is to check if the strings' are truncated or not. So, >= should
> be used instead of >, because strlcat() and snprintf() return the length of
> the output, excluding the trailing NULL.
> 
> Fixes: a02d69261134 ("SUNRPC: Provide functions for managing universal addresses")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Hi Christophe -

Should these two be taken via the NFS client tree or do you intend
to include them in some other tree?


> ---
> v2: Fix cut'n'paste typo in subject
>     Add net in [PATCH...]
> ---
>  net/sunrpc/addr.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
> index d435bffc6199..97ff11973c49 100644
> --- a/net/sunrpc/addr.c
> +++ b/net/sunrpc/addr.c
> @@ -284,10 +284,10 @@ char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
>  	}
>  
>  	if (snprintf(portbuf, sizeof(portbuf),
> -		     ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
> +		     ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf))
>  		return NULL;
>  
> -	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
> +	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf))
>  		return NULL;
>  
>  	return kstrdup(addrbuf, gfp_flags);
> -- 
> 2.32.0
>
Jakub Kicinski Oct. 25, 2023, 4:28 p.m. UTC | #3
On Wed, 25 Oct 2023 10:30:51 -0400 Chuck Lever wrote:
> Should these two be taken via the NFS client tree or do you intend
> to include them in some other tree?

FWIW we're not intending to take these. If only get_maintainer
understood tree designations :(
Dan Carpenter Oct. 27, 2023, 11:49 a.m. UTC | #4
On Wed, Oct 25, 2023 at 09:28:29AM -0700, Jakub Kicinski wrote:
> On Wed, 25 Oct 2023 10:30:51 -0400 Chuck Lever wrote:
> > Should these two be taken via the NFS client tree or do you intend
> > to include them in some other tree?
> 
> FWIW we're not intending to take these. If only get_maintainer
> understood tree designations :(

I accidentally markedt his NFS patch as net on Oct 11 as well.  :/

https://lore.kernel.org/all/356fb42c-9cf1-45cd-9233-ac845c507fb7@moroto.mountain/

regards,
dan carpenter
diff mbox series

Patch

diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
index d435bffc6199..97ff11973c49 100644
--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -284,10 +284,10 @@  char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
 	}
 
 	if (snprintf(portbuf, sizeof(portbuf),
-		     ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
+		     ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf))
 		return NULL;
 
-	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
+	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf))
 		return NULL;
 
 	return kstrdup(addrbuf, gfp_flags);