From: Sungbae Yoo Date: Mon, 4 Dec 2017 02:52:38 +0000 (+0900) Subject: Add exception handler for regex_error X-Git-Tag: submit/tizen_4.0/20171206.014509^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1546d7cf7a49560dcc4cb156afeaaa8d34cbd852;p=platform%2Fcore%2Fsecurity%2Fklay.git Add exception handler for regex_error This commit is to resolve the SVACE issue Signed-off-by: Sungbae Yoo Change-Id: I73541b858d1cbca66a2800737869d506acfef02e --- diff --git a/src/cgroup.cpp b/src/cgroup.cpp index c04f6bb..a4b6aca 100644 --- a/src/cgroup.cpp +++ b/src/cgroup.cpp @@ -34,8 +34,12 @@ namespace runtime { bool Cgroup::existSubsystem(const std::string& name) { - if (!std::regex_match(name, std::regex(NAME_PATTERN))) { - return false; + try { + if (!std::regex_match(name, std::regex(NAME_PATTERN))) { + return false; + } + } catch (std::runtime_error &e) { + throw runtime::Exception("Unexpected regex error"); } runtime::File dir("/sys/fs/cgroup/" + name); @@ -51,8 +55,12 @@ bool Cgroup::existSubsystem(const std::string& name) void Cgroup::createSubsystem(const std::string& name) { - if (!std::regex_match(name, std::regex(NAME_PATTERN))) { - throw runtime::Exception("Invalid subsystem name"); + try { + if (!std::regex_match(name, std::regex(NAME_PATTERN))) { + throw runtime::Exception("Invalid subsystem name"); + } + } catch (std::runtime_error &e) { + throw runtime::Exception("Unexpected regex error"); } if (existSubsystem(name)) { @@ -110,8 +118,12 @@ void Cgroup::destroySubsystem(const std::string& name) bool Cgroup::exist(const std::string& subsystem, const std::string& path) { - if (!std::regex_match(path, std::regex(PATH_PATTERN))) { - return false; + try { + if (!std::regex_match(path, std::regex(PATH_PATTERN))) { + return false; + } + } catch (std::runtime_error &e) { + throw runtime::Exception("Unexpected regex error"); } runtime::File dir("/sys/fs/cgroup/" + subsystem + "/" + path); @@ -127,8 +139,12 @@ bool Cgroup::exist(const std::string& subsystem, const std::string& path) void Cgroup::create(const std::string& subsystem, const std::string& path) { - if (!std::regex_match(path, std::regex(PATH_PATTERN))) { - throw runtime::Exception("Invalid path"); + try { + if (!std::regex_match(path, std::regex(PATH_PATTERN))) { + throw runtime::Exception("Invalid path"); + } + } catch (std::runtime_error &e) { + throw runtime::Exception("Unexpected regex error"); } if (exist(subsystem, path)) {