aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjenkins4kodi <jenkins4kodi@users.noreply.github.com>2017-05-24 20:56:06 +0200
committerGitHub <noreply@github.com>2017-05-24 20:56:06 +0200
commite4a88ae1fec514f74cf3d12208669b366c5df1b3 (patch)
tree87da0bae8c9624d300ae57b4a11c1c0923d334b4
parent4f53fb5bf524ce6a0c226677bbb052aa7d10a35b (diff)
parentc2077a2d938c819858fa6fbe94f4a5c9f19edc2c (diff)
Merge pull request #12155 from Rechi/fixRegexGcc48Krypton
-rw-r--r--xbmc/filesystem/ZipManager.cpp6
-rw-r--r--xbmc/filesystem/ZipManager.h3
-rw-r--r--xbmc/filesystem/test/TestZipManager.cpp24
3 files changed, 20 insertions, 13 deletions
diff --git a/xbmc/filesystem/ZipManager.cpp b/xbmc/filesystem/ZipManager.cpp
index f2c697312b..e60f99fd31 100644
--- a/xbmc/filesystem/ZipManager.cpp
+++ b/xbmc/filesystem/ZipManager.cpp
@@ -30,6 +30,7 @@
#include "utils/CharsetConverter.h"
#include "utils/EndianSwap.h"
#include "utils/log.h"
+#include "utils/RegExp.h"
#include "utils/URIUtils.h"
using namespace XFILE;
@@ -172,6 +173,9 @@ bool CZipManager::GetZipList(const CURL& url, std::vector<SZipEntry>& items)
// Go to the start of central directory
mFile.Seek(cdirOffset,SEEK_SET);
+ CRegExp pathTraversal;
+ pathTraversal.RegComp(PATH_TRAVERSAL);
+
char temp[CHDR_SIZE];
while (mFile.GetPosition() < cdirOffset + cdirSize)
{
@@ -199,7 +203,7 @@ bool CZipManager::GetZipList(const CURL& url, std::vector<SZipEntry>& items)
// Jump after central file header extra field and file comment
mFile.Seek(ze.eclength + ze.clength,SEEK_CUR);
- if (!std::regex_search(strName, PATH_TRAVERSAL))
+ if (pathTraversal.RegFind(strName) < 0)
items.push_back(ze);
}
diff --git a/xbmc/filesystem/ZipManager.h b/xbmc/filesystem/ZipManager.h
index 93243b9b2c..90fe19f5fa 100644
--- a/xbmc/filesystem/ZipManager.h
+++ b/xbmc/filesystem/ZipManager.h
@@ -32,14 +32,13 @@
#define ECDREC_SIZE 22
#include <memory.h>
-#include <regex>
#include <string>
#include <vector>
#include <map>
class CURL;
-static const std::regex PATH_TRAVERSAL(R"_((^|\/|\\)\.{2}($|\/|\\))_");
+static const std::string PATH_TRAVERSAL(R"_((^|\/|\\)\.{2}($|\/|\\))_");
struct SZipEntry {
unsigned int header;
diff --git a/xbmc/filesystem/test/TestZipManager.cpp b/xbmc/filesystem/test/TestZipManager.cpp
index b72dbb6327..825f1d093b 100644
--- a/xbmc/filesystem/test/TestZipManager.cpp
+++ b/xbmc/filesystem/test/TestZipManager.cpp
@@ -19,20 +19,24 @@
*/
#include "filesystem/ZipManager.h"
+#include "utils/RegExp.h"
#include "gtest/gtest.h"
TEST(TestZipManager, PathTraversal)
{
- ASSERT_TRUE(std::regex_search("..", PATH_TRAVERSAL));
- ASSERT_TRUE(std::regex_search("../test.txt", PATH_TRAVERSAL));
- ASSERT_TRUE(std::regex_search("..\\test.txt", PATH_TRAVERSAL));
- ASSERT_TRUE(std::regex_search("test/../test.txt", PATH_TRAVERSAL));
- ASSERT_TRUE(std::regex_search("test\\../test.txt", PATH_TRAVERSAL));
- ASSERT_TRUE(std::regex_search("test\\..\\test.txt", PATH_TRAVERSAL));
+ CRegExp pathTraversal;
+ pathTraversal.RegComp(PATH_TRAVERSAL);
- ASSERT_FALSE(std::regex_search("...", PATH_TRAVERSAL));
- ASSERT_FALSE(std::regex_search("..test.txt", PATH_TRAVERSAL));
- ASSERT_FALSE(std::regex_search("test.txt..", PATH_TRAVERSAL));
- ASSERT_FALSE(std::regex_search("test..test.txt", PATH_TRAVERSAL));
+ ASSERT_TRUE(pathTraversal.RegFind("..") >= 0);
+ ASSERT_TRUE(pathTraversal.RegFind("../test.txt") >= 0);
+ ASSERT_TRUE(pathTraversal.RegFind("..\\test.txt") >= 0);
+ ASSERT_TRUE(pathTraversal.RegFind("test/../test.txt") >= 0);
+ ASSERT_TRUE(pathTraversal.RegFind("test\\../test.txt") >= 0);
+ ASSERT_TRUE(pathTraversal.RegFind("test\\..\\test.txt") >= 0);
+
+ ASSERT_FALSE(pathTraversal.RegFind("...") >= 0);
+ ASSERT_FALSE(pathTraversal.RegFind("..test.txt") >= 0);
+ ASSERT_FALSE(pathTraversal.RegFind("test.txt..") >= 0);
+ ASSERT_FALSE(pathTraversal.RegFind("test..test.txt") >= 0);
}