]> Sergey Matveev's repositories - btrtrc.git/blobdiff - tracker/udp/announce.go
Add http and udp tracker server implementations
[btrtrc.git] / tracker / udp / announce.go
index 59b6c6cfa728e8b7c694de89074d24b200da0341..b5c9f8ffbaa317651c0d8a73b4272d96c84e38e6 100644 (file)
@@ -38,7 +38,12 @@ func (me *AnnounceEvent) UnmarshalText(text []byte) error {
 var announceEventStrings = []string{"", "completed", "started", "stopped"}
 
 func (e AnnounceEvent) String() string {
-       // See BEP 3, "event", and https://github.com/anacrolix/torrent/issues/416#issuecomment-751427001.
+       // See BEP 3, "event", and
+       // https://github.com/anacrolix/torrent/issues/416#issuecomment-751427001. Return a safe default
+       // in case event values are not sanitized.
+       if e < 0 || int(e) >= len(announceEventStrings) {
+               return ""
+       }
        return announceEventStrings[e]
 }