From 260b5572384501245cfe8dfa243c67d0c5a7c6a9 Mon Sep 17 00:00:00 2001 From: Tom Almeida <3256078+Tommoa@users.noreply.github.com> Date: Tue, 3 Aug 2021 22:17:50 +0800 Subject: [PATCH] Properly handle gateway responses that return Javascript errors (#74) This was previously causing a segmentation fault, as the gateway response would not be valid XML to be parsed. Closes: #38, #71 --- GPClient/gatewayauthenticator.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GPClient/gatewayauthenticator.cpp b/GPClient/gatewayauthenticator.cpp index eb71c33..222af78 100644 --- a/GPClient/gatewayauthenticator.cpp +++ b/GPClient/gatewayauthenticator.cpp @@ -44,8 +44,9 @@ void GatewayAuthenticator::login(const LoginParams ¶ms) void GatewayAuthenticator::onLoginFinished() { QNetworkReply *reply = qobject_cast(sender()); + QByteArray response; - if (reply->error()) { + if (reply->error() || (response = reply->readAll()).contains("Authentication failure")) { PLOGE << QString("Failed to login the gateway at %1, %2").arg(loginUrl).arg(reply->errorString()); if (normalLoginWindow) { @@ -61,7 +62,7 @@ void GatewayAuthenticator::onLoginFinished() normalLoginWindow->close(); } - const QUrlQuery params = gpclient::helper::parseGatewayResponse(reply->readAll()); + const QUrlQuery params = gpclient::helper::parseGatewayResponse(response); emit success(params.toString()); }