From b8361e4f9e70afb70e24cbc6f1dddc402f1fd25f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 25 Oct 2018 07:45:13 +1000 Subject: [PATCH] [outh2] Don't crash when trying to parse an invalid json configuration file --- src/auth/oauth2/qgsauthoauth2config.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/auth/oauth2/qgsauthoauth2config.cpp b/src/auth/oauth2/qgsauthoauth2config.cpp index 6c480b27dda..0cbd367eefe 100644 --- a/src/auth/oauth2/qgsauthoauth2config.cpp +++ b/src/auth/oauth2/qgsauthoauth2config.cpp @@ -334,7 +334,16 @@ bool QgsAuthOAuth2Config::loadConfigTxt( QgsDebugMsg( QStringLiteral( "Error parsing JSON: %1" ).arg( QString( errStr ) ) ); return res; } - QJsonWrapper::qvariant2qobject( variant.toMap(), this ); + const QVariantMap variantMap = variant.toMap(); + // safety check -- qvariant2qobject asserts if an non-matching property is found in the json + for ( QVariantMap::const_iterator iter = variantMap.constBegin(); iter != variantMap.constEnd(); ++iter ) + { + QVariant property = this->property( iter.key().toLatin1() ); + if ( !property.isValid() ) // e.g. not a auth config json file + return false; + } + + QJsonWrapper::qvariant2qobject( variantMap, this ); break; } default: