From 3d23c8df2582a6b0e44e048d431ecb00a14667ec Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 1 Nov 2025 13:37:35 +0100 Subject: [PATCH] openat2: Fix invalid memory access on Cygwin. * lib/openat2.c (do_openat2): Don't use an expression with side effects as argument of ISSLASH. --- ChangeLog | 6 ++++++ lib/openat2.c | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8d0aa9f023..116b967c54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-11-01 Bruno Haible + + openat2: Fix invalid memory access on Cygwin. + * lib/openat2.c (do_openat2): Don't use an expression with side effects + as argument of ISSLASH. + 2025-11-01 Bruno Haible openat2 tests: Avoid gratuitous test failure when debugging. diff --git a/lib/openat2.c b/lib/openat2.c index ee64d05836..4ad4e88f6c 100644 --- a/lib/openat2.c +++ b/lib/openat2.c @@ -267,8 +267,12 @@ do_openat2 (int *fd, char const *filename, } } idx_t h = g; - while (1 < h && !ISSLASH (e[- --h])) - continue; + while (h > 1) + { + h--; + if (ISSLASH (e[-h])) + break; + } /* Properties of the file name through the first component's end, or to file name end if there is no component. */ -- 2.47.3