1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

TCPGet: Last property check (hopefully) (#1059)

* Add additional safety checks to avoid acting on non-existent objects

* TCPGet: yet more checks
This commit is contained in:
Nathanaël Lécaudé 2016-11-18 06:25:06 -05:00 committed by Dave Conway-Jones
parent eef59fd40e
commit 5f5aa0b2f7

View File

@ -492,6 +492,7 @@ module.exports = function(RED) {
buf[i] = data[j]; buf[i] = data[j];
i += 1; i += 1;
if ( i >= node.splitc) { if ( i >= node.splitc) {
if (clients[connection_id]) {
clients[connection_id].msg.payload = new Buffer(i); clients[connection_id].msg.payload = new Buffer(i);
buf.copy(clients[connection_id].msg.payload,0,0,i); buf.copy(clients[connection_id].msg.payload,0,0,i);
node.send(clients[connection_id].msg); node.send(clients[connection_id].msg);
@ -502,11 +503,13 @@ module.exports = function(RED) {
i = 0; i = 0;
} }
} }
}
// look for a char // look for a char
else { else {
buf[i] = data[j]; buf[i] = data[j];
i += 1; i += 1;
if (data[j] == node.splitc) { if (data[j] == node.splitc) {
if (clients[connection_id]) {
clients[connection_id].msg.payload = new Buffer(i); clients[connection_id].msg.payload = new Buffer(i);
buf.copy(clients[connection_id].msg.payload,0,0,i); buf.copy(clients[connection_id].msg.payload,0,0,i);
node.send(clients[connection_id].msg); node.send(clients[connection_id].msg);
@ -519,6 +522,7 @@ module.exports = function(RED) {
} }
} }
} }
}
}); });
clients[connection_id].client.on('end', function() { clients[connection_id].client.on('end', function() {
@ -560,8 +564,10 @@ module.exports = function(RED) {
}); });
} }
else { else {
if (clients[connection_id] && clients[connection_id].client) {
clients[connection_id].client.write(clients[connection_id].msg.payload); clients[connection_id].client.write(clients[connection_id].msg.payload);
} }
}
}); });
this.on("close", function(done) { this.on("close", function(done) {