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,14 +492,16 @@ module.exports = function(RED) {
buf[i] = data[j]; buf[i] = data[j];
i += 1; i += 1;
if ( i >= node.splitc) { if ( i >= node.splitc) {
clients[connection_id].msg.payload = new Buffer(i); if (clients[connection_id]) {
buf.copy(clients[connection_id].msg.payload,0,0,i); clients[connection_id].msg.payload = new Buffer(i);
node.send(clients[connection_id].msg); buf.copy(clients[connection_id].msg.payload,0,0,i);
if (clients[connection_id].client) { node.send(clients[connection_id].msg);
node.status({}); clients[connection_id].client.destroy(); if (clients[connection_id].client) {
delete clients[connection_id]; node.status({}); clients[connection_id].client.destroy();
delete clients[connection_id];
}
i = 0;
} }
i = 0;
} }
} }
// look for a char // look for a char
@ -507,14 +509,16 @@ module.exports = function(RED) {
buf[i] = data[j]; buf[i] = data[j];
i += 1; i += 1;
if (data[j] == node.splitc) { if (data[j] == node.splitc) {
clients[connection_id].msg.payload = new Buffer(i); if (clients[connection_id]) {
buf.copy(clients[connection_id].msg.payload,0,0,i); clients[connection_id].msg.payload = new Buffer(i);
node.send(clients[connection_id].msg); buf.copy(clients[connection_id].msg.payload,0,0,i);
if (clients[connection_id].client) { node.send(clients[connection_id].msg);
node.status({}); clients[connection_id].client.destroy(); if (clients[connection_id].client) {
delete clients[connection_id]; node.status({}); clients[connection_id].client.destroy();
delete clients[connection_id];
}
i = 0;
} }
i = 0;
} }
} }
} }
@ -560,7 +564,9 @@ module.exports = function(RED) {
}); });
} }
else { else {
clients[connection_id].client.write(clients[connection_id].msg.payload); if (clients[connection_id] && clients[connection_id].client) {
clients[connection_id].client.write(clients[connection_id].msg.payload);
}
} }
}); });