lkml.org 
[lkml]   [2023]   [Oct]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH net v2] net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr()
    Date
    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(-)

    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
    \
     
     \ /
      Last update: 2023-10-25 00:00    [W:8.567 / U:0.024 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site