]> git.baikalelectronics.ru Git - kernel.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)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Wed, 27 May 2020 14:08:26 +0000 (10:08 -0400)
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>
net/sunrpc/addr.c

index 8b4d72b1a0667bb0070d96fe482e43e2327d61e5..010dcb876f9d72dc85b5e4ff327e927999b7d242 100644 (file)
@@ -82,11 +82,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);