aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2017-07-18 01:01:24 +0200
committerRon Yorston <rmy@pobox.com>2017-08-24 08:37:25 +0100
commit0933725e0f33fa93256623933813381c62611bfd (patch)
treed9dcb7b504d898d6c854f645271bb13b58f805d9
parent8efbd67183ccc98ce343ea0c69b62c8b75573c9f (diff)
downloadbusybox-w32-0933725e0f33fa93256623933813381c62611bfd.tar.gz
busybox-w32-0933725e0f33fa93256623933813381c62611bfd.tar.bz2
busybox-w32-0933725e0f33fa93256623933813381c62611bfd.zip
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 <johannes.schindelin@gmx.de> Signed-off-by: Ron Yorston <rmy@pobox.com>
-rw-r--r--libbb/get_last_path_component.c10
1 files 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 @@
10 10
11const char* FAST_FUNC bb_basename(const char *name) 11const char* FAST_FUNC bb_basename(const char *name)
12{ 12{
13 const char *cp = strrchr(name, '/');
14 if (cp)
15 return cp + 1;
16#if ENABLE_PLATFORM_MINGW32 13#if ENABLE_PLATFORM_MINGW32
17 cp = strrchr(name, '\\'); 14 const char *cp;
15 for (cp = name; *cp; cp++)
16 if (*cp == '/' || *cp == '\\')
17 name = cp + 1;
18#else
19 const char *cp = strrchr(name, '/');
18 if (cp) 20 if (cp)
19 return cp + 1; 21 return cp + 1;
20#endif 22#endif