diff options
author | 2016-04-10 17:21:32 +1000 | |
---|---|---|
committer | 2016-04-10 17:21:46 +1000 | |
commit | 7d1ec41744172cb9b36212d78afb8713ff7ced57 (patch) | |
tree | 535c63d3f05da5b4aa6b8f27948210ebac08c476 | |
parent | cceb3a32b786790495e846dd8c4d1684cce3a5dc (diff) |
foobar is not a subdirectory of foo called bar
-rw-r--r-- | src/lib/util/unzip.cpp | 2 | ||||
-rw-r--r-- | src/lib/util/zippath.cpp | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/lib/util/unzip.cpp b/src/lib/util/unzip.cpp index b0b64a5df3b..bf7891f0258 100644 --- a/src/lib/util/unzip.cpp +++ b/src/lib/util/unzip.cpp @@ -639,7 +639,7 @@ int zip_file_impl::search(std::uint32_t search_crc, const std::string &search_fi // FIXME: if (!is_utf8) convert filename to UTF8 (assume CP437 or something) // chop off trailing slash for directory entries - bool const is_dir(!m_header.file_name.empty() && (*m_header.file_name.rbegin() == '/')); + bool const is_dir(!m_header.file_name.empty() && (m_header.file_name.back() == '/')); if (is_dir) m_header.file_name.resize(m_header.file_name.length() - 1); // check to see if it matches query diff --git a/src/lib/util/zippath.cpp b/src/lib/util/zippath.cpp index 32f2161d0b6..1e4fb6dd293 100644 --- a/src/lib/util/zippath.cpp +++ b/src/lib/util/zippath.cpp @@ -871,24 +871,28 @@ void zippath_closedir(zippath_directory *directory) static const char *get_relative_path(zippath_directory const &directory) { auto len = directory.zipprefix.length(); - const char *prefix = directory.zipprefix.c_str(); + char const *prefix = directory.zipprefix.c_str(); while (is_zip_file_separator(*prefix)) { len--; prefix++; } - if ((len <= directory.zipfile->current_name().length()) && - !strncmp(prefix, directory.zipfile->current_name().c_str(), len)) + std::string const ¤t(directory.zipfile->current_name()); + char const *result = directory.zipfile->current_name().c_str() + len; + if ((current.length() >= len) && + !strncmp(prefix, current.c_str(), len) && + (!*prefix || is_zip_file_separator(*result) || is_zip_file_separator(directory.zipprefix.back()))) { - const char *result = &directory.zipfile->current_name().c_str()[len]; while (is_zip_file_separator(*result)) result++; return *result ? result : nullptr; } - - return nullptr; + else + { + return nullptr; + } } |