]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
who: fix only-theoretical overflow
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2023 18:21:25 +0000 (11:21 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 31 Jul 2023 18:21:43 +0000 (11:21 -0700)
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.

src/system.h

index db1a6773b91249404056690cf9ec08e0164d4ed2..2d9c47f48b073386033f813db364c38a9539cb54 100644 (file)
@@ -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;