0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-02 03:32:52 +01:00

ircd:Ⓜ️:fed: Fix cache content buffer overwrite causing erroneous well-known fallback results.

This commit is contained in:
Jason Volk 2020-05-05 16:09:36 -07:00
parent 970f84304e
commit 7d949427e3

View file

@ -1722,16 +1722,16 @@ try
const_buffer{} const_buffer{}
}; };
const json::string cached
{
content["m.server"]
};
const seconds ttl const seconds ttl
{ {
content.get<time_t>("ttl", time_t(86400)) content.get<time_t>("ttl", time_t(86400))
}; };
const string_view cached
{
data(buf), move(buf, json::string(content["m.server"]))
};
const system_point expires const system_point expires
{ {
origin_server_ts + ttl origin_server_ts + ttl
@ -1756,14 +1756,8 @@ try
const string_view delegated const string_view delegated
{ {
expired || !valid? expired || !valid?
fetch_well_known(buf, origin): fetch_well_known(buf + size(cached), origin):
cached
// Move the returned string to the front of the buffer; this overwrites
// other data fetched by the cache query to focus on just the result.
string_view
{
data(buf), move(buf, cached)
}
}; };
// Branch on valid cache hit to return result. // Branch on valid cache hit to return result.
@ -1804,10 +1798,7 @@ try
timef(tmbuf, expires, localtime), timef(tmbuf, expires, localtime),
}; };
return string_view return cached;
{
data(buf), move(buf, cached)
};
} }
// Any time the well-known result is the same as the origin (that // Any time the well-known result is the same as the origin (that