Browse Source

Check host corresponding to HostId exists

Miro Kuratczyk 9 years ago
parent
commit
0048dc6e7c
1 changed files with 7 additions and 2 deletions
  1. 7 2
      psiphon/server/psinet/psinet.go

+ 7 - 2
psiphon/server/psinet/psinet.go

@@ -370,14 +370,19 @@ func bucketizeServerList(servers []Server, bucketCount int) [][]Server {
 // Newer clients ignore the legacy fields and only utilize the extended (new) config.
 func (db *Database) getEncodedServerEntry(server Server) string {
 
-	host := db.Hosts[server.HostId]
+	host, hostExists := db.Hosts[server.HostId]
+	if !hostExists {
+		return ""
+	}
 
 	// TCS web server certificate has PEM headers and newlines, so strip those now
 	// for legacy format compatibility
 	webServerCertificate := server.WebServerCertificate
 	if host.IsTCS {
 		splitCert := strings.Split(server.WebServerCertificate, "\n")
-		if (len(splitCert) > 2) {
+		if (len(splitCert) <= 2) {
+			webServerCertificate = ""
+		} else {
 			webServerCertificate = strings.Join(splitCert[1:len(splitCert)-2], "")
 		}
 	}