Fix a potential bug of UnboundLocalError (#8329)

Replaced with less buggier control flow
This commit is contained in:
Jonathan de Jong 2020-09-17 12:54:56 +02:00 committed by GitHub
parent a3f124b821
commit 53284c425e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

1
changelog.d/8329.bugfix Normal file
View File

@ -0,0 +1 @@
Fix UnboundLocalError from occuring when appservices send malformed register request.

View File

@ -431,11 +431,14 @@ class RegisterRestServlet(RestServlet):
access_token = self.auth.get_access_token_from_request(request) access_token = self.auth.get_access_token_from_request(request)
if isinstance(desired_username, str): if not isinstance(desired_username, str):
result = await self._do_appservice_registration( raise SynapseError(400, "Desired Username is missing or not a string")
desired_username, access_token, body
) result = await self._do_appservice_registration(
return 200, result # we throw for non 200 responses desired_username, access_token, body
)
return 200, result
# == Normal User Registration == (everyone else) # == Normal User Registration == (everyone else)
if not self._registration_enabled: if not self._registration_enabled: