From 936f2faf619cb018a3e4493785ed1ad166ca15d8 Mon Sep 17 00:00:00 2001 From: claudio Date: Tue, 20 Feb 2024 10:36:23 +0000 Subject: [PATCH] Add missing check for the case where the pattern hits a barrier before the string is consumed as well. Right now a string of 'dir1/' and a pattern of 'dir/' will result in an infinite loop because matchsub() would return success but then would not move forward. Report and diff from Kyle Evans (kevans FreeBSD.org) OK tb@ --- usr.bin/rsync/rmatch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr.bin/rsync/rmatch.c b/usr.bin/rsync/rmatch.c index 0fe01dcb77f..920ef25d67f 100644 --- a/usr.bin/rsync/rmatch.c +++ b/usr.bin/rsync/rmatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rmatch.c,v 1.3 2022/12/26 19:16:02 jmc Exp $ */ +/* $OpenBSD: rmatch.c,v 1.4 2024/02/20 10:36:23 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker @@ -260,8 +260,12 @@ matchsub(const char **pp, const char **ss, const char *end, int wild) /* eat possible escape char before '/' */ if (pattern[0] == '\\' && pattern[1] == '/') pattern++; - if (pattern[0] == '/') + if (pattern[0] == '/') { + /* hit the barrier but we still have characters left */ + if (string < end) + return 1; break; + } /* check if there are still characters available to compare */ if (string >= end) -- 2.20.1