Skip to content

Commit b8361e4

Browse files
committed
[outh2] Don't crash when trying to parse an invalid json configuration file
1 parent b5dc84d commit b8361e4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/auth/oauth2/qgsauthoauth2config.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,16 @@ bool QgsAuthOAuth2Config::loadConfigTxt(
334334
QgsDebugMsg( QStringLiteral( "Error parsing JSON: %1" ).arg( QString( errStr ) ) );
335335
return res;
336336
}
337-
QJsonWrapper::qvariant2qobject( variant.toMap(), this );
337+
const QVariantMap variantMap = variant.toMap();
338+
// safety check -- qvariant2qobject asserts if an non-matching property is found in the json
339+
for ( QVariantMap::const_iterator iter = variantMap.constBegin(); iter != variantMap.constEnd(); ++iter )
340+
{
341+
QVariant property = this->property( iter.key().toLatin1() );
342+
if ( !property.isValid() ) // e.g. not a auth config json file
343+
return false;
344+
}
345+
346+
QJsonWrapper::qvariant2qobject( variantMap, this );
338347
break;
339348
}
340349
default:

0 commit comments

Comments
 (0)