Add exception handler for regex_error 92/162492/2 accepted/tizen/4.0/unified/20171207.070735 accepted/tizen/unified/20171206.115938 submit/tizen/20171206.014519 submit/tizen_4.0/20171206.014509 submit/tizen_4.0/20171206.042433
authorSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 4 Dec 2017 02:52:38 +0000 (11:52 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 4 Dec 2017 02:54:31 +0000 (02:54 +0000)
This commit is to resolve the SVACE issue

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I73541b858d1cbca66a2800737869d506acfef02e

src/cgroup.cpp

index c04f6bb94a38510d673ec3f77417e4401017fa85..a4b6acabb20077a6b81666f47face3ca948d4acd 100644 (file)
@@ -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)) {