]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
net: sunrpc: Fix off-by-one issues in 'rpc_ntop6'
authorFedor Tokarev <ftokarev@gmail.com>
Sat, 28 Mar 2020 11:56:55 +0000 (14:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jun 2020 13:41:55 +0000 (15:41 +0200)
[ Upstream commit 118917d696dc59fd3e1741012c2f9db2294bed6f ]

Fix off-by-one issues in 'rpc_ntop6':
 - 'snprintf' returns the number of characters which would have been
   written if enough space had been available, excluding the terminating
   null byte. Thus, a return value of 'sizeof(scopebuf)' means that the
   last character was dropped.
 - 'strcat' adds a terminating null byte to the string, thus if len ==
   buflen, the null byte is written past the end of the buffer.

Signed-off-by: Fedor Tokarev <ftokarev@gmail.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sunrpc/addr.c

index 2e0a6f92e563d7942b3bf7fa17b43e3f44dc9355..8391c2785550135d270b1039f5a7b7670aa05ef7 100644 (file)
@@ -81,11 +81,11 @@ static size_t rpc_ntop6(const struct sockaddr *sap,
 
        rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
                        IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id);
-       if (unlikely((size_t)rc > sizeof(scopebuf)))
+       if (unlikely((size_t)rc >= sizeof(scopebuf)))
                return 0;
 
        len += rc;
-       if (unlikely(len > buflen))
+       if (unlikely(len >= buflen))
                return 0;
 
        strcat(buf, scopebuf);