From 9f0b057c14fbd341f3cd1b6a42744b8406fa2544 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Mon, 16 Aug 2021 14:40:58 +0200 Subject: [PATCH] TNetwork: Fix crash when auth response is not a JSON object --- src/TNetwork.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 0162f9f..ff0f739 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -295,23 +295,24 @@ void TNetwork::Authentication(SOCKET TCPSock) { return; } - if (!AuthResponse.IsObject() && Rc != "0") { - ClientKick(*Client, "Backend returned invalid auth response format."); - error("Backend returned invalid auth response format. This should never happen."); - auto Lock = Sentry.CreateExclusiveContext(); - Sentry.SetContext("auth", - { { "response-body", Rc }, - { "key", RequestString } }); - Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target); - Sentry.Log(SentryLevel::Error, "default", "unexpected backend response (" + std::to_string(ResponseCode) + ")"); - return; - } else if (Rc == "0") { - auto Lock = Sentry.CreateExclusiveContext(); - Sentry.SetContext("auth", - { { "response-body", Rc }, - { "key", RequestString } }); - Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target); - Sentry.Log(SentryLevel::Info, "default", "backend returned 0 instead of json (" + std::to_string(ResponseCode) + ")"); + if (!AuthResponse.IsObject()) { + if (Rc == "0") { + auto Lock = Sentry.CreateExclusiveContext(); + Sentry.SetContext("auth", + { { "response-body", Rc }, + { "key", RequestString } }); + Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target); + Sentry.Log(SentryLevel::Info, "default", "backend returned 0 instead of json (" + std::to_string(ResponseCode) + ")"); + } else { // Rc != "0" + ClientKick(*Client, "Backend returned invalid auth response format."); + error("Backend returned invalid auth response format. This should never happen."); + auto Lock = Sentry.CreateExclusiveContext(); + Sentry.SetContext("auth", + { { "response-body", Rc }, + { "key", RequestString } }); + Sentry.SetTransaction(Application::GetBackendUrlForAuth() + Target); + Sentry.Log(SentryLevel::Error, "default", "unexpected backend response (" + std::to_string(ResponseCode) + ")"); + } return; }