Skip to content
Permalink
Browse files

[oauth2] Verify replies still exist and attribute gets are valid

Fixes unreported crash, due to access on nonexistent replies.
  • Loading branch information
dakcarto committed May 17, 2019
1 parent 04ee8e0 commit eedc582d0114704d0b13c23eecf104ad639a90ed
Showing with 27 additions and 5 deletions.
  1. +27 −5 src/auth/oauth2/qgsauthoauth2method.cpp
@@ -388,6 +388,12 @@ void QgsAuthOAuth2Method::onReplyFinished()
{
QgsMessageLog::logMessage( tr( "Network reply finished" ), AUTH_METHOD_KEY, Qgis::MessageLevel::Info );
QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
if ( !reply )
{
QString msg = tr( "Network reply finished but no reply object accessible" );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Warning );
return;
}
QgsMessageLog::logMessage( tr( "Results: %1" ).arg( QString( reply->readAll() ) ),
AUTH_METHOD_KEY, Qgis::MessageLevel::Info );
}
@@ -411,12 +417,22 @@ void QgsAuthOAuth2Method::onNetworkError( QNetworkReply::NetworkError err )

// TODO: update debug messages to output to QGIS

int status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt();
msg = tr( "Network error, HTTP status: %1" ).arg(
reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString() );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info );
QVariant status = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
if ( !status.isValid() )
{
msg = tr( "Network error but no reply object attributes found" );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Warning );
return;
}
QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
if ( phrase.isValid() )
{
msg = tr( "Network error, HTTP status: %1" ).arg( phrase.toString() );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info );
}

if ( status == 401 )

if ( status.toInt() == 401 )
{
msg = tr( "Attempting token refresh..." );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Info );
@@ -452,6 +468,12 @@ void QgsAuthOAuth2Method::onNetworkError( QNetworkReply::NetworkError err )
void QgsAuthOAuth2Method::onRefreshFinished( QNetworkReply::NetworkError err )
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
if ( !reply )
{
QString msg = tr( "Token refresh finished but no reply object accessible" );
QgsMessageLog::logMessage( msg, AUTH_METHOD_KEY, Qgis::MessageLevel::Warning );
return;
}
if ( err != QNetworkReply::NoError )
{
QgsMessageLog::logMessage( tr( "Token refresh error: %1" ).arg( reply->errorString() ),

0 comments on commit eedc582

Please sign in to comment.
You can’t perform that action at this time.