From f244fb5f61f764ab2aff76b0b1b9d85e8ea1e751 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 18 Sep 2014 20:28:58 +0000 Subject: Fix inability to access locations starting with a slash. Thanks to Jean-Yves Moulin for reporting this issue. When bbackupd is configured to create locations whose names contain a slash, it was impossible to escape it, and thus to enter the directory in bbackupquery to inspect or restore it. --- lib/common/Utils.cpp | 37 ++++++++++++++++++++++++++----------- lib/common/Utils.h | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'lib/common') diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index f3541648..ddb79ba8 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -51,25 +51,40 @@ std::string GetBoxBackupVersion() // Created: 2003/07/31 // // -------------------------------------------------------------------------- -void SplitString(const std::string &String, char SplitOn, std::vector &rOutput) +void SplitString(std::string String, char SplitOn, std::vector &rOutput) { // Split it up. - std::string::size_type b = 0; - std::string::size_type e = 0; - while(e = String.find_first_of(SplitOn, b), e != String.npos) + std::string::size_type begin = 0, end = 0, pos = 0; + + while(end = String.find_first_of(SplitOn, pos), end != String.npos) { - // Get this string - unsigned int len = e - b; - if(len >= 1) + // Is it preceded by the escape character? + if(end > 0 && String[end - 1] == '\\') + { + // Ignore this one, don't change begin, let the next + // match/fallback consume it instead. But remove the + // backslash from the string, and set pos to the + // current position, which no longer contains a + // separator character. + String.erase(end - 1, 1); + pos = end; + } + else { - rOutput.push_back(String.substr(b, len)); + // Extract the substring and move past it. + unsigned int len = end - begin; + if(len >= 1) + { + rOutput.push_back(String.substr(begin, len)); + } + begin = end + 1; + pos = begin; } - b = e + 1; } // Last string - if(b < String.size()) + if(begin < String.size()) { - rOutput.push_back(String.substr(b)); + rOutput.push_back(String.substr(begin)); } /*#ifndef BOX_RELEASE_BUILD BOX_TRACE("Splitting string '" << String << " on " << (char)SplitOn); diff --git a/lib/common/Utils.h b/lib/common/Utils.h index 3134245a..636fb487 100644 --- a/lib/common/Utils.h +++ b/lib/common/Utils.h @@ -17,7 +17,7 @@ std::string GetBoxBackupVersion(); -void SplitString(const std::string &String, char SplitOn, std::vector &rOutput); +void SplitString(std::string String, char SplitOn, std::vector &rOutput); #ifdef SHOW_BACKTRACE_ON_EXCEPTION void DumpStackBacktrace(); -- cgit v1.2.3