mirror of
https://github.com/ergochat/ergo.git
synced 2025-06-06 23:07:32 +02:00
improve robustness of timestamp parsing (#2250)
* Clamp CHATHISTORY timestamp selectors to be in [0, MaxInt64] * Convert everything to UTC up front (probably a no-op)
This commit is contained in:
parent
2cf569c5d9
commit
54b17b0700
@ -755,6 +755,14 @@ func chathistoryHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
|||||||
return
|
return
|
||||||
} else if identifier == "timestamp" {
|
} else if identifier == "timestamp" {
|
||||||
timestamp, err = time.Parse(IRCv3TimestampFormat, value)
|
timestamp, err = time.Parse(IRCv3TimestampFormat, value)
|
||||||
|
if err == nil {
|
||||||
|
timestamp = timestamp.UTC()
|
||||||
|
if timestamp.Before(unixEpoch) {
|
||||||
|
timestamp = unixEpoch
|
||||||
|
} else if timestamp.After(year2262Problem) {
|
||||||
|
timestamp = year2262Problem
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -3052,6 +3060,7 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
|
|||||||
rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp"))
|
rb.Add(nil, server.name, "FAIL", "MARKREAD", "INVALID_PARAMS", utils.SafeErrorParam(readTimestamp), client.t("Invalid timestamp"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
readTime = readTime.UTC()
|
||||||
result := client.SetReadMarker(cftarget, readTime)
|
result := client.SetReadMarker(cftarget, readTime)
|
||||||
readTimestamp = fmt.Sprintf("timestamp=%s", result.Format(IRCv3TimestampFormat))
|
readTimestamp = fmt.Sprintf("timestamp=%s", result.Format(IRCv3TimestampFormat))
|
||||||
// inform the originating session whether it was a success or a no-op:
|
// inform the originating session whether it was a success or a no-op:
|
||||||
|
@ -65,6 +65,9 @@ var (
|
|||||||
throttleMessage = "You have attempted to connect too many times within a short duration. Wait a while, and you will be able to connect."
|
throttleMessage = "You have attempted to connect too many times within a short duration. Wait a while, and you will be able to connect."
|
||||||
|
|
||||||
httpVerbs = utils.SetLiteral("CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE")
|
httpVerbs = utils.SetLiteral("CONNECT", "DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT", "TRACE")
|
||||||
|
|
||||||
|
unixEpoch = time.Unix(0, 0).UTC()
|
||||||
|
year2262Problem = time.Unix(0, 1<<63-1).UTC() // this is the maximum time for which (*time.Time).UnixNano() is well-defined
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is the main Oragono server.
|
// Server is the main Oragono server.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user