diff --git a/src/libs/network.cpp b/src/libs/network.cpp index c9689aca1..78e8bbb3b 100644 --- a/src/libs/network.cpp +++ b/src/libs/network.cpp @@ -466,7 +466,7 @@ Network::Id Network::HttpCreateTemplate(Id http_ctx_id, const char* user_agent, HttpTemplate tn {}; tn.used = true; tn.http_ver = http_ver; - tn.user_agent = std::string(user_agent); + tn.user_agent = user_agent != nullptr ? user_agent : ""; tn.is_auto_proxy_conf = is_auto_proxy_conf; tn.http_ctx_id = http_ctx_id.GetId(); tn.nonblock = false; diff --git a/tests/HttpUriParseTests.cpp b/tests/HttpUriParseTests.cpp index 819e88f1c..14c1f5372 100644 --- a/tests/HttpUriParseTests.cpp +++ b/tests/HttpUriParseTests.cpp @@ -1,4 +1,5 @@ #include "common/abi.h" +#include "libs/network.h" #include "loader/symbolDatabase.h" #include @@ -162,6 +163,17 @@ void TestBuildHonoursOption(HttpUriParse parse, HttpUriBuild build) { CHECK(BuildWith(build, element, 0) == url); } +// Cyberpunk 2077 (PPSA03974) creates a template with a NULL user agent. +void TestTemplateWithoutUserAgent() { + using namespace Libs::Network; + Initialize(); + const int pool = Net::NetPoolCreate("http", 0x10000, 0); + const int ssl = Ssl::SslInit(0x10000); + const int http = Http::HttpInit(pool, ssl, 0x10000); + CHECK(Http::HttpCreateTemplate(http, nullptr, 2, 1) > 0); + Shutdown(); +} + } // namespace int main() { @@ -176,5 +188,6 @@ int main() { TestAbsentQuery(parse); TestEmptyUri(parse); TestPresentQuery(parse); + TestTemplateWithoutUserAgent(); return failures == 0 ? 0 : 1; }