{"action":"created","issue":{"url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/14","repository_url":"https://api.github.com/repos/dresende/node-modbus-tcp","labels_url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/14/comments","events_url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/14/events","html_url":"https://github.com/dresende/node-modbus-tcp/pull/14","id":137857229,"number":14,"title":"Fix pending buffer length check","user":{"login":"relovution","id":590613,"avatar_url":"https://avatars.githubusercontent.com/u/590613?v=3","gravatar_id":"","url":"https://api.github.com/users/relovution","html_url":"https://github.com/relovution","followers_url":"https://api.github.com/users/relovution/followers","following_url":"https://api.github.com/users/relovution/following{/other_user}","gists_url":"https://api.github.com/users/relovution/gists{/gist_id}","starred_url":"https://api.github.com/users/relovution/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/relovution/subscriptions","organizations_url":"https://api.github.com/users/relovution/orgs","repos_url":"https://api.github.com/users/relovution/repos","events_url":"https://api.github.com/users/relovution/events{/privacy}","received_events_url":"https://api.github.com/users/relovution/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-03-02T12:08:25Z","updated_at":"2016-09-27T11:07:21Z","closed_at":"2016-09-27T11:07:11Z","pull_request":{"url":"https://api.github.com/repos/dresende/node-modbus-tcp/pulls/14","html_url":"https://github.com/dresende/node-modbus-tcp/pull/14","diff_url":"https://github.com/dresende/node-modbus-tcp/pull/14.diff","patch_url":"https://github.com/dresende/node-modbus-tcp/pull/14.patch"},"body":"We need more than just 6 bytes for a packet to make sense. At the very least 8, since we unconditionally readUInt8 from position 6 and 7 (lines 42 & 43), but even then every possible valid Modbus TCP message has at least from (2 bytes) and to (2 bytes) fields, unless I am overlooking something.\r\n\r\nWithout this, it's trivial to DoS the modbus-tcp Server, e.g. by sending 6 0x00 bytes which will lead to an uncaught exception:\r\n\r\nRangeError: Trying to access beyond buffer length\r\n\r\nRangeError: Trying to access beyond buffer length\r\n    at checkOffset (buffer.js:582:11)\r\n    at Buffer.readUInt16BE (buffer.js:602:5)\r\n    at ReadStream._transform ([...]/node_modules/modbus-tcp/lib/Server/ReadStream.js:66:24)\r\n    at ReadStream._write ([...]/node_modules/modbus-tcp/lib/Server/ReadStream.js:105:18)\r\n    at doWrite (_stream_writable.js:226:10)\r\n    at writeOrBuffer (_stream_writable.js:216:5)\r\n    at ReadStream.Writable.write (_stream_writable.js:183:11)\r\n    at write (_stream_readable.js:602:24)\r\n    at flow (_stream_readable.js:611:7)\r\n    at Socket.pipeOnReadable (_stream_readable.js:643:5)\r\n    at Socket.emit (events.js:92:17)\r\n    at emitReadable_ (_stream_readable.js:427:10)\r\n"},"comment":{"url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/comments/249834684","html_url":"https://github.com/dresende/node-modbus-tcp/pull/14#issuecomment-249834684","issue_url":"https://api.github.com/repos/dresende/node-modbus-tcp/issues/14","id":249834684,"user":{"login":"dresende","id":157494,"avatar_url":"https://avatars.githubusercontent.com/u/157494?v=3","gravatar_id":"","url":"https://api.github.com/users/dresende","html_url":"https://github.com/dresende","followers_url":"https://api.github.com/users/dresende/followers","following_url":"https://api.github.com/users/dresende/following{/other_user}","gists_url":"https://api.github.com/users/dresende/gists{/gist_id}","starred_url":"https://api.github.com/users/dresende/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dresende/subscriptions","organizations_url":"https://api.github.com/users/dresende/orgs","repos_url":"https://api.github.com/users/dresende/repos","events_url":"https://api.github.com/users/dresende/events{/privacy}","received_events_url":"https://api.github.com/users/dresende/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T11:07:21Z","updated_at":"2016-09-27T11:07:21Z","body":"Sorry for the delay."}}
{"actor":{"display_login":"dresende"}}