diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2018-02-16 17:21:48 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-02-16 17:21:48 +0100 |
commit | 26bcedda20c88c7bfbcef106dbb240b8b591cf59 (patch) | |
tree | 38dea2134a8369372dd9d12b370bb8e65253cf06 /winsup/utils | |
parent | f881942d771ec027aef4b101bd6582fbd1543181 (diff) | |
download | newlib-26bcedda20c88c7bfbcef106dbb240b8b591cf59.zip newlib-26bcedda20c88c7bfbcef106dbb240b8b591cf59.tar.gz newlib-26bcedda20c88c7bfbcef106dbb240b8b591cf59.tar.bz2 |
Cygwin: fix utils path handling in case cygdrive path is just '/'
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/utils')
-rw-r--r-- | winsup/utils/path.cc | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/winsup/utils/path.cc b/winsup/utils/path.cc index a76cf76..fcc5c07 100644 --- a/winsup/utils/path.cc +++ b/winsup/utils/path.cc @@ -672,7 +672,7 @@ read_mounts () */ static int -path_prefix_p (const char *path1, const char *path2, int len1) +path_prefix_p (const char *path1, const char *path2, size_t len1) { /* Handle case where PATH1 has trailing '/' and when it doesn't. */ if (len1 > 0 && isslash (path1[len1 - 1])) @@ -778,7 +778,7 @@ rel_vconcat (const char *cwd, const char *s, va_list v) cwd = pathbuf; } - int max_len = -1; + int max_len = 0; mnt_t *m, *match = NULL; for (m = mount_table; m->posix; m++) @@ -786,7 +786,7 @@ rel_vconcat (const char *cwd, const char *s, va_list v) if (m->flags & MOUNT_CYGDRIVE) continue; - int n = strlen (m->native); + size_t n = strlen (m->native); if (n < max_len || !path_prefix_p (m->native, cwd, n)) continue; max_len = n; @@ -821,7 +821,7 @@ rel_vconcat (const char *cwd, const char *s, va_list v) static char * vcygpath (const char *cwd, const char *s, va_list v) { - int max_len = -1; + size_t max_len = 0; mnt_t *m, *match = NULL; if (!max_mount_entry) @@ -843,15 +843,23 @@ vcygpath (const char *cwd, const char *s, va_list v) for (m = mount_table; m->posix; m++) { - int n = strlen (m->posix); + size_t n = strlen (m->posix); if (n < max_len || !path_prefix_p (m->posix, path, n)) continue; - if ((m->flags & MOUNT_CYGDRIVE) - && ((int) strlen (path) < n + 2 - || path[n] != '/' - || !isalpha (path[n + 1]) - || path[n + 2] != '/')) - continue; + if (m->flags & MOUNT_CYGDRIVE) + { + if (strlen (path) < n + 2) + continue; + /* If cygdrive path is just '/', fix n for followup evaluation. */ + if (n == 1) + n = 0; + if (path[n] != '/') + continue; + if (!isalpha (path[n + 1])) + continue; + if (path[n + 2] != '/') + continue; + } max_len = n; match = m; } @@ -859,7 +867,7 @@ vcygpath (const char *cwd, const char *s, va_list v) char *native; if (match == NULL) native = strdup (path); - else if (max_len == (int) strlen (path)) + else if (max_len == strlen (path)) native = strdup (match->native); else if (match->flags & MOUNT_CYGDRIVE) { |