Handle the case when hoststring is empty.

BUG=chromium:480536
R=magjed@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/46109004

Cr-Commit-Position: refs/heads/master@{#9081}
diff --git a/talk/app/webrtc/peerconnection.cc b/talk/app/webrtc/peerconnection.cc
index 46cae4c..457007a 100644
--- a/talk/app/webrtc/peerconnection.cc
+++ b/talk/app/webrtc/peerconnection.cc
@@ -106,8 +106,8 @@
 bool GetServiceTypeAndHostnameFromUri(const std::string& in_str,
                                       ServiceType* service_type,
                                       std::string* hostname) {
-  std::string::size_type colonpos = in_str.find(':');
-  if (colonpos == std::string::npos) {
+  const std::string::size_type colonpos = in_str.find(':');
+  if (colonpos == std::string::npos || (colonpos + 1) == in_str.length()) {
     return false;
   }
   std::string type = in_str.substr(0, colonpos);
@@ -218,13 +218,19 @@
       continue;
     }
 
+    ASSERT(!hoststring.empty());
+
     // Let's break hostname.
     tokens.clear();
     rtc::tokenize(hoststring, '@', &tokens);
-    hoststring = tokens[0];
-    if (tokens.size() == kTurnHostTokensNum) {
+    ASSERT(!tokens.empty());
+    // TODO(pthatcher): What's the right thing to do if tokens.size() is >2?
+    // E.g. a string like "foo@bar@bat".
+    if (tokens.size() >= kTurnHostTokensNum) {
       server.username = rtc::s_url_decode(tokens[0]);
       hoststring = tokens[1];
+    } else {
+      hoststring = tokens[0];
     }
 
     int port = kDefaultStunPort;
@@ -239,7 +245,6 @@
       continue;
     }
 
-
     if (port <= 0 || port > 0xffff) {
       LOG(WARNING) << "Invalid port: " << port;
       continue;