Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix a potential bug of UnboundLocalError (#8329)
Browse files Browse the repository at this point in the history
Replaced with less buggier control flow
  • Loading branch information
ShadowJonathan committed Sep 17, 2020
1 parent a3f124b commit 53284c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.d/8329.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix UnboundLocalError from occuring when appservices send malformed register request.
13 changes: 8 additions & 5 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,14 @@ async def on_POST(self, request):

access_token = self.auth.get_access_token_from_request(request)

if isinstance(desired_username, str):
result = await self._do_appservice_registration(
desired_username, access_token, body
)
return 200, result # we throw for non 200 responses
if not isinstance(desired_username, str):
raise SynapseError(400, "Desired Username is missing or not a string")

result = await self._do_appservice_registration(
desired_username, access_token, body
)

return 200, result

# == Normal User Registration == (everyone else)
if not self._registration_enabled:
Expand Down

0 comments on commit 53284c4

Please sign in to comment.