]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Avoid panic in AnnounceEvent.String
authorMatt Joiner <anacrolix@gmail.com>
Thu, 29 Dec 2022 08:41:09 +0000 (19:41 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 29 Dec 2022 08:41:09 +0000 (19:41 +1100)
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]
 }