update_engine: Check for available candidate urls before setting current url

This patch checks if there is any candidate url before accessing elements in the
array that keeps the urls. This happens if the url_index_ is advanced and saved
in the prefs.

BUG=chromium:831815
TEST=unittest
TEST=set current-url-index to 1 manually, and restarted the UE, it didn't crash.

Change-Id: I13929fad10725655a464d54317e040de5036bc04
Reviewed-on: https://chromium-review.googlesource.com/1012761
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: David Haddock <dhaddock@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/payload_state.h b/payload_state.h
index 24e9900..4ec5bf9 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -80,7 +80,8 @@
   }
 
   inline std::string GetCurrentUrl() override {
-    return candidate_urls_.size() && candidate_urls_[payload_index_].size()
+    return (payload_index_ < candidate_urls_.size() &&
+            url_index_ < candidate_urls_[payload_index_].size())
                ? candidate_urls_[payload_index_][url_index_]
                : "";
   }
@@ -374,9 +375,10 @@
   void ResetRollbackVersion();
 
   inline uint32_t GetUrlIndex() {
-    return url_index_ ? std::min(candidate_urls_[payload_index_].size() - 1,
-                                 url_index_)
-                      : 0;
+    return (url_index_ != 0 && payload_index_ < candidate_urls_.size())
+               ? std::min(candidate_urls_[payload_index_].size() - 1,
+                          url_index_)
+               : 0;
   }
 
   // Computes the list of candidate URLs from the total list of payload URLs in