Skip to content

Commit

Permalink
Catch exceptions at the identifier parsing stage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Aug 9, 2023
1 parent cfc61a1 commit 2f389fc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,24 @@ class AnisetteService {
return;
}

auto res = parseJSON(socket.receiveText());
ubyte[] requestedIdentifier = Base64.decode(res["identifier"].str());
log.infoF!"[>> %s] Got it."(requestUUID);
string identifier;
try {
auto res = parseJSON(socket.receiveText());
ubyte[] requestedIdentifier = Base64.decode(res["identifier"].str());
log.infoF!"[>> %s] Got it."(requestUUID);

if (requestedIdentifier.length != 16) {
identifier = UUID(requestedIdentifier[0..16]).toString();
} catch (Exception ex) {
JSONValue response = [
"result": "InvalidIdentifier"
];

log.infoF!"[>> %s] It is invalid."(requestUUID);
log.infoF!"[>> %s] It is invalid: %s"(requestUUID, ex);
socket.send(response.toString(JSONOptions.doNotEscapeSlashes));
socket.close();
return;
}

string identifier = UUID(requestedIdentifier[0..16]).toString();
log.infoF!("[<< %s] Correct identifier (%s).")(requestUUID, identifier);

GC.disable(); // garbage collector can deallocate ADI parts since it can't find the pointers.
Expand Down Expand Up @@ -344,7 +346,7 @@ class AnisetteService {

uint session;
try {
res = parseJSON(socket.receiveText());
auto res = parseJSON(socket.receiveText());

string spim = res["spim"].str();
log.infoF!"[<< %s] Received SPIM."(requestUUID);
Expand Down Expand Up @@ -380,7 +382,7 @@ class AnisetteService {
}

try {
res = parseJSON(socket.receiveText());
auto res = parseJSON(socket.receiveText());
string ptm = res["ptm"].str();
string tk = res["tk"].str();
log.infoF!"[<< %s] Received PTM and TK."(requestUUID);
Expand Down

0 comments on commit 2f389fc

Please sign in to comment.