From 9610cbc09e72c370369b5cc0e165542a2c5fdca7 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Sun, 6 Aug 2023 22:27:27 -0500 Subject: [PATCH] patch: don't run off the end of path if it ends in '/'. Found by fuzzing (afl) in OpenBSD. Obtained from: OpenBSD (CVS 1.65) --- usr.bin/patch/pch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index d1d71f95644c..e180c7075712 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1618,7 +1618,8 @@ num_components(const char *path) size_t n; const char *cp; - for (n = 0, cp = path; (cp = strchr(cp, '/')) != NULL; n++, cp++) { + for (n = 0, cp = path; (cp = strchr(cp, '/')) != NULL; n++) { + cp++; while (*cp == '/') cp++; /* skip consecutive slashes */ }