From 6815c51784f1172c71fba89530ab52ca06b54b1e Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Thu, 24 Sep 2020 19:11:20 +0200 Subject: [PATCH] Fixed bug whereby a failed read would cause a null pointer deref in tristanable as the data array would be empty and .ptr is being used so bounds checking code would not apply --- source/dnetd/dconnection.d | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 42eb685..eca00bd 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -94,14 +94,20 @@ public class DConnection : Thread bool status = receiveMessage(socket, receivedBytes); /* TODO: Check status */ + if(status) + { + /* Decode the tristanable message (tagged message) */ + receivedMessage = DataMessage.decode(receivedBytes); - /* Decode the tristanable message (tagged message) */ - receivedMessage = DataMessage.decode(receivedBytes); + /* Process the message */ + process(receivedMessage); - /* Process the message */ - process(receivedMessage); - - /* TODO: Tristanable needs reserved-tag support (client-side concern) */ + /* TODO: Tristanable needs reserved-tag support (client-side concern) */ + } + else + { + /* TODO: Error handling */ + } } } @@ -192,8 +198,8 @@ public class DConnection : Thread /* Set the type of this connection to `server` */ connType = ConnectionType.SERVER; } - /* If `register` command (requires: unauthed) */ - else if(commandByte == 2 && !hasAuthed) + /* If `register` command (requires: unauthed, client) */ + else if(commandByte == 2 && !hasAuthed && connType == ConnectionType.CLIENT) { } @@ -290,8 +296,8 @@ public class DConnection : Thread /* TODO: Implement me, use return value */ writeSocket(tag, reply); } - /* If `msg` command (requires: authed) */ - else if(commandByte == 7 && hasAuthed) + /* If `msg` command (requires: authed, client) */ + else if(commandByte == 7 && hasAuthed && connType == ConnectionType.CLIENT) { /* Status */ bool status = true;