From patchwork Tue Oct 24 21:58:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 13435315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE967C25B6B for ; Tue, 24 Oct 2023 21:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344425AbjJXV6b (ORCPT ); Tue, 24 Oct 2023 17:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234970AbjJXV6b (ORCPT ); Tue, 24 Oct 2023 17:58:31 -0400 Received: from smtp.smtpout.orange.fr (smtp-30.smtpout.orange.fr [80.12.242.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A5D110C9 for ; Tue, 24 Oct 2023 14:58:28 -0700 (PDT) Received: from localhost.localdomain ([141.170.221.62]) by smtp.orange.fr with ESMTPA id vPPuqJHBw1FecvPPuqURbW; Tue, 24 Oct 2023 23:58:27 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1698184707; bh=CxvDITTYWkbVF3erY431KvtkoAIB2u79w80t/0Puphk=; h=From:To:Cc:Subject:Date; b=bfAt2zU/U5AFUmH1D1n1lI5TdIRFOhOYxVQrrCy1n21xgIA8oAbl0E7GEcV0J31t4 2dNamly3ACkpzHZXMY6i3Jj/BeZ9W8lJaVTUr1GQ9A4JoIM5A9y2EPgkfKQhOnhjAT cVXQVj18euEh+SGpRScXfLE4CTLDjSe1mUZkqHYTWenzHCawJsNdSDRfg5opbWDif3 Ee3nNVaQxzyzu+5oThrra2CV6NJOh86HGhTeHlklONpAx/+Hxu8T0Vt0frpX6Q2OQ7 mklUw9VRu+ePWscJ1QhuyME3BGWJ2JjNaYHHIGG9+INTE0QTHHovEoEqlPdOLSOqoT r8V4jRMmwu9Lg== X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Tue, 24 Oct 2023 23:58:27 +0200 X-ME-IP: 141.170.221.62 From: Christophe JAILLET To: chuck.lever@oracle.com, jlayton@kernel.org, neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com, tom@talpey.com, trond.myklebust@hammerspace.com, anna@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH net v2] net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr() Date: Tue, 24 Oct 2023 23:58:20 +0200 Message-Id: <31b27c8e54f131b7eabcbd78573f0b5bfe380d8c.1698184674.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 Reviewed-by: Benjamin Coddington --- 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);