summaryrefslogtreecommitdiff
path: root/lib/common/Utils.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-18 20:28:58 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-18 20:28:58 +0000
commitf244fb5f61f764ab2aff76b0b1b9d85e8ea1e751 (patch)
tree2d647f99e09ae631cfd91fd3c7b76e3c378578ef /lib/common/Utils.cpp
parent172fcf113f39d79b074f0c28f30aa96329a7390a (diff)
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.
Diffstat (limited to 'lib/common/Utils.cpp')
-rw-r--r--lib/common/Utils.cpp37
1 files changed, 26 insertions, 11 deletions
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<std::string> &rOutput)
+void SplitString(std::string String, char SplitOn, std::vector<std::string> &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);