From 0933725e0f33fa93256623933813381c62611bfd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 18 Jul 2017 01:01:24 +0200 Subject: bb_basename: handle mixed slashes correctly A path like C:/WINDOWS\system32 was handled incorrectly: it found the forward slash, and then never bothered to look whether there was another (back-)slash later on. This fixes e.g. running BusyBox as C:/test\sh.exe Signed-off-by: Johannes Schindelin Signed-off-by: Ron Yorston --- libbb/get_last_path_component.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libbb/get_last_path_component.c b/libbb/get_last_path_component.c index 15eb85ca8..3a9b9237e 100644 --- a/libbb/get_last_path_component.c +++ b/libbb/get_last_path_component.c @@ -10,11 +10,13 @@ const char* FAST_FUNC bb_basename(const char *name) { - const char *cp = strrchr(name, '/'); - if (cp) - return cp + 1; #if ENABLE_PLATFORM_MINGW32 - cp = strrchr(name, '\\'); + const char *cp; + for (cp = name; *cp; cp++) + if (*cp == '/' || *cp == '\\') + name = cp + 1; +#else + const char *cp = strrchr(name, '/'); if (cp) return cp + 1; #endif -- cgit v1.2.3-55-g6feb