From 9cbda6e1f8fdd4d7ffae26edcabceb239ed14ece Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Mon, 31 Jul 2023 11:21:25 -0700
Subject: [PATCH] who: fix only-theoretical overflow
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change stzncpy’s implementation to match its comment, in the case
where SRC + LEN would overflow.  This case never happens in coreutils.
* src/system.h (stzncpy): Work even if SRC + LEN would overflow.

Reference:https://github.com/coreutils/coreutils/commit/9cbda6e1f8fdd4d7ffae26edcabceb239ed14ece
Conflict:NA

---
 src/system.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/system.h b/src/system.h
index db1a6773b..2d9c47f48 100644
--- a/src/system.h
+++ b/src/system.h
@@ -781,8 +781,8 @@ write_error (void)
 static inline char *
 stzncpy (char *restrict dest, char const *restrict src, size_t len)
 {
-  char const *src_end = src + len;
-  while (src < src_end && *src)
+  size_t i;
+  for (i = 0; i < len && *src; i++)
     *dest++ = *src++;
   *dest = 0;
   return dest;
-- 
2.27.0

