[Archive] Double check if iterator is valid.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 3 Jun 2015 13:11:39 +0000 (15:11 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 3 Jun 2015 13:11:39 +0000 (15:11 +0200)
Prevent CID: 388883

[Verification] TCT pass rate: 100%

Change-Id: I5af48b3473108d6802000c69395e04d95ca0dbdf
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
src/archive/archive_instance.cc

index 478042618be2be8b4ff40deabbbbc29c3b40566a..d4ca1792b60b64847a660abc1fe290b5e014576c 100755 (executable)
@@ -568,12 +568,20 @@ void ArchiveInstance::Extract(const picojson::value& args, picojson::object& out
 
     //Not found but if our name does not contain '/'
     //try looking for directory with such name
-    if (it == entries->end() && !isDirectoryPath(v_entry_name.get<std::string>())) {
+    if (entries->end() == it && !isDirectoryPath(v_entry_name.get<std::string>())) {
         const std::string try_directory = v_entry_name.get<std::string>() + "/";
         LoggerD("GetEntryByName Trying directory: [%s]", try_directory.c_str());
         it = entries->find(try_directory);
     }
 
+    if (entries->end() == it) {
+        LoggerE("Failed to find entry");
+        PostError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to find entry"), callbackId);
+        delete callback;
+        callback = NULL;
+        return;
+    }
+
     result = it->second->extractTo(callback);
     if (result.error_code() != ErrorCode::NO_ERROR) {
         LoggerE("ArchiveFileEntry.extractTo error");