Repository: syncthing/syncthing (language: go)

Issue:
Behavior of discovery server doesn't match documentation
- **stdiscosrv** v1.18.6 "Fermium Flea" (go1.17.6 linux-amd64) teamcity@build.syncthing.net 2021-12-30 12:07:01 UTC [purego]

According to [documentation][1] :

> Discosrv will listen on the replication port **only** when `-replicate` is given. The default replication listen address is “:19200”.


but in fact, even if the option `-replicate` wasn't given at start, `stdiscosrv` will listening on all interfaces on default port for replication

```
# ss -lntp
```
|State | Recv-Q |  Send-Q |  Local Address:Port |  Peer Address:Port |   Process|
|--------|-----------|-------------|-----------------------------|---------------------------|-------------|
|`LISTEN` |  `0`     |         `4096`   |     ` *:19200`          |              `*:*`                 |  users:(("stdiscosrv",pid=1781059,fd=12))|



[1]: https://docs.syncthing.net/users/stdiscosrv.html



Discussion / hints:

Fix patch:
diff --git a/cmd/stdiscosrv/main.go b/cmd/stdiscosrv/main.go
index f1e96e0659e..5c22fe83d72 100644
--- a/cmd/stdiscosrv/main.go
+++ b/cmd/stdiscosrv/main.go
@@ -116,8 +116,11 @@ func main() {
 	var replicationDestinations []string
 	parts := strings.Split(replicationPeers, ",")
 	for _, part := range parts {
-		fields := strings.Split(part, "@")
+		if part == "" {
+			continue
+		}
 
+		fields := strings.Split(part, "@")
 		switch len(fields) {
 		case 2:
 			// This is an id@address specification. Grab the address for the
@@ -137,6 +140,9 @@ func main() {
 			if err != nil {
 				log.Fatalln("Parsing device ID:", err)
 			}
+			if id == protocol.EmptyDeviceID {
+				log.Fatalf("Missing device ID for peer in %q", part)
+			}
 			allowedReplicationPeers = append(allowedReplicationPeers, id)
 
 		default:


Test patch: