coreutils/backport-who-fix-only-theoretical-overflow.patch
fly_fzc b1840f7ab9 coreutils:sync patches from community
(cherry picked from commit c77ff335ff89d7cb9ad7caaa6f19d3437996991d)
2023-10-10 15:09:34 +08:00

38 lines
1.1 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 stzncpys 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