forked from OpenGamers/abaddon
validate iso8601 when parsing to snowflake
This commit is contained in:
@@ -1923,7 +1923,7 @@ void DiscordClient::HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &m
|
|||||||
if (override.Muted) {
|
if (override.Muted) {
|
||||||
if (override.MuteConfig.EndTime.has_value()) {
|
if (override.MuteConfig.EndTime.has_value()) {
|
||||||
const auto end = Snowflake::FromISO8601(*override.MuteConfig.EndTime);
|
const auto end = Snowflake::FromISO8601(*override.MuteConfig.EndTime);
|
||||||
if (end > now)
|
if (end.IsValid() && end > now)
|
||||||
now_muted_channels.insert(override.ChannelID);
|
now_muted_channels.insert(override.ChannelID);
|
||||||
} else {
|
} else {
|
||||||
now_muted_channels.insert(override.ChannelID);
|
now_muted_channels.insert(override.ChannelID);
|
||||||
@@ -2325,7 +2325,7 @@ void DiscordClient::HandleReadyGuildSettings(const ReadyEventData &data) {
|
|||||||
if (entry.Muted) {
|
if (entry.Muted) {
|
||||||
if (entry.MuteConfig.EndTime.has_value()) {
|
if (entry.MuteConfig.EndTime.has_value()) {
|
||||||
const auto end = Snowflake::FromISO8601(*entry.MuteConfig.EndTime);
|
const auto end = Snowflake::FromISO8601(*entry.MuteConfig.EndTime);
|
||||||
if (end > now)
|
if (end.IsValid() && end > now)
|
||||||
m_muted_guilds.insert(entry.GuildID);
|
m_muted_guilds.insert(entry.GuildID);
|
||||||
} else {
|
} else {
|
||||||
m_muted_guilds.insert(entry.GuildID);
|
m_muted_guilds.insert(entry.GuildID);
|
||||||
@@ -2335,7 +2335,7 @@ void DiscordClient::HandleReadyGuildSettings(const ReadyEventData &data) {
|
|||||||
if (override.Muted) {
|
if (override.Muted) {
|
||||||
if (override.MuteConfig.EndTime.has_value()) {
|
if (override.MuteConfig.EndTime.has_value()) {
|
||||||
const auto end = Snowflake::FromISO8601(*override.MuteConfig.EndTime);
|
const auto end = Snowflake::FromISO8601(*override.MuteConfig.EndTime);
|
||||||
if (end > now)
|
if (end.IsValid() && end > now)
|
||||||
m_muted_channels.insert(override.ChannelID);
|
m_muted_channels.insert(override.ChannelID);
|
||||||
} else {
|
} else {
|
||||||
m_muted_channels.insert(override.ChannelID);
|
m_muted_channels.insert(override.ChannelID);
|
||||||
|
|||||||
@@ -42,9 +42,11 @@ Snowflake Snowflake::FromNow() {
|
|||||||
Snowflake Snowflake::FromISO8601(std::string_view ts) {
|
Snowflake Snowflake::FromISO8601(std::string_view ts) {
|
||||||
int yr, mon, day, hr, min, sec, tzhr, tzmin;
|
int yr, mon, day, hr, min, sec, tzhr, tzmin;
|
||||||
float milli;
|
float milli;
|
||||||
std::sscanf(ts.data(), "%d-%d-%dT%d:%d:%d%f+%d:%d",
|
if (std::sscanf(ts.data(), "%d-%d-%dT%d:%d:%d%f+%d:%d",
|
||||||
&yr, &mon, &day, &hr, &min, &sec, &milli, &tzhr, &tzmin);
|
&yr, &mon, &day, &hr, &min, &sec, &milli, &tzhr, &tzmin) != 9) return Snowflake::Invalid;
|
||||||
return SecondsInterval * (util::TimeToEpoch(yr, mon, day, hr, min, sec) - DiscordEpochSeconds) + static_cast<uint64_t>(milli * static_cast<float>(SecondsInterval));
|
const auto epoch = util::TimeToEpoch(yr, mon, day, hr, min, sec);
|
||||||
|
if (epoch < DiscordEpochSeconds) return Snowflake::Invalid;
|
||||||
|
return SecondsInterval * (epoch - DiscordEpochSeconds) + static_cast<uint64_t>(milli * static_cast<float>(SecondsInterval));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Snowflake::IsValid() const {
|
bool Snowflake::IsValid() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user