glibc/backport-Fix-invalid-pointer-dereference-in-wcpcpy_chk.patch
shixuantong 1982405ab3 Fix invalid pointer dereference in wcpcpy_chk and wcscpy_chk
(cherry picked from commit eb2474daa03e009409d5070d7d822cab56da5169)
2023-12-29 16:32:48 +08:00

36 lines
941 B
Diff

From 4ee824be757337d8444fdc320aa1ca3e4397c906 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Tue, 21 Jun 2022 15:57:48 +0100
Subject: [PATCH] Fix invalid pointer dereference in wcpcpy_chk
The src pointer is const and points to a different object, so accessing
dest via src is invalid.
Reviewed-by: Florian Weimer <fweimer@redhat.com>
---
debug/wcpcpy_chk.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/debug/wcpcpy_chk.c b/debug/wcpcpy_chk.c
index 0e1d381a..16410e17 100644
--- a/debug/wcpcpy_chk.c
+++ b/debug/wcpcpy_chk.c
@@ -29,13 +29,12 @@ __wcpcpy_chk (wchar_t *dest, const wchar_t *src, size_t destlen)
{
wchar_t *wcp = (wchar_t *) dest - 1;
wint_t c;
- const ptrdiff_t off = src - dest + 1;
do
{
if (__glibc_unlikely (destlen-- == 0))
__chk_fail ();
- c = wcp[off];
+ c = *src++;
*++wcp = c;
}
while (c != L'\0');
--
2.27.0