Fix wgt version checking logic 42/250742/2
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 4 Jan 2021 07:37:39 +0000 (16:37 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 4 Jan 2021 07:55:00 +0000 (16:55 +0900)
WGT version string could contain non UTF-8 characters.
Now version checking logic will skip validation
if given character is non UTF-8.

Change-Id: I869fab0b8f12ece90735e71a71ec62b0e84c806c
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/wgt/step/configuration/step_parse.cc

index d4c677b..3b46e7e 100644 (file)
@@ -171,14 +171,22 @@ std::set<std::string> StepParse::ExtractPrivileges(
 }
 
 std::string StepParse::GetPackageVersion(
-     const std::string& manifest_version) {
-  if (manifest_version.empty()) {
+    const std::string& manifest_version) {
+  if (manifest_version.empty())
     return kManifestVersion;
-  }
-  std::string version = manifest_version.substr(0,
-      manifest_version.find_first_not_of("1234567890."));
 
-  return version;
+  for (const char& c : manifest_version) {
+    // first bit of 1 byte utf-8 character is always 0
+    if (c >> 7 == 1)
+      continue;
+
+    if (std::string(1, c).find_first_not_of("1234567890.") !=
+        std::string::npos) {
+      LOG(ERROR) << "Invalid version format";
+      return nullptr;
+    }
+  }
+  return manifest_version;
 }
 
 bool StepParse::FillInstallationInfo(manifest_x* manifest) {