{"action":"created","issue":{"url":"https://api.github.com/repos/mscdex/ssh2/issues/472","repository_url":"https://api.github.com/repos/mscdex/ssh2","labels_url":"https://api.github.com/repos/mscdex/ssh2/issues/472/labels{/name}","comments_url":"https://api.github.com/repos/mscdex/ssh2/issues/472/comments","events_url":"https://api.github.com/repos/mscdex/ssh2/issues/472/events","html_url":"https://github.com/mscdex/ssh2/issues/472","id":178243543,"number":472,"title":"Buffer full when issuing first command","user":{"login":"straydogz","id":22337141,"avatar_url":"https://avatars.githubusercontent.com/u/22337141?v=3","gravatar_id":"","url":"https://api.github.com/users/straydogz","html_url":"https://github.com/straydogz","followers_url":"https://api.github.com/users/straydogz/followers","following_url":"https://api.github.com/users/straydogz/following{/other_user}","gists_url":"https://api.github.com/users/straydogz/gists{/gist_id}","starred_url":"https://api.github.com/users/straydogz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/straydogz/subscriptions","organizations_url":"https://api.github.com/users/straydogz/orgs","repos_url":"https://api.github.com/users/straydogz/repos","events_url":"https://api.github.com/users/straydogz/events{/privacy}","received_events_url":"https://api.github.com/users/straydogz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-21T04:29:51Z","updated_at":"2016-09-21T04:42:55Z","closed_at":null,"body":"We are having an issue when attempting to connect to our clients SFTP server, that once we have gotten a SFTP session established it errors on the first command / request. However when we connect to our test server there are no issues.\r\n\r\nThis is the code snipet of the test code;\r\n\r\n```js\r\nsocks.connect({\r\n  host: remote_host, // test sftp server destination\r\n  port: 22,\r\n  proxyHost: proxy_hostname,\r\n  proxyPort: 1080,\r\n  auths: [ socks.auth.UserPassword( username, pass ) ],\r\n  debug: function ( string ) { console.dir(string); }\t  \t\t\r\n}, function(socket) {\r\n  var conn = new ssh2.Client();\r\n  conn.on('ready', function() {\r\n    console.log(\"### Client :: Ready\");\r\n    conn.sftp(function(err, sftp) {\r\n      if (err) throw err;\r\n\r\n      // you'll be able to use sftp here\r\n      console.log(\"### SFTP session created\");\r\n\r\n      // command #1 - Read the directory\r\n      sftp.readdir(\"/\", function(err, list) {\r\n        if (err) throw err;\r\n\r\n        // List the directory in the console\r\n        console.dir(list);\r\n        // Do not forget to close the connection, otherwise you'll get troubles\r\n        conn.end();\r\n      });\r\n\r\n      // Use sftp to execute tasks like .unlink or chmod etc \t\r\n    });\r\n  }).connect({\r\n    // using the proxy socket instead of host / port combination\r\n    sock: socket,\r\n    algorithms: {\r\n      kex: ['diffie-hellman-group1-sha1', 'diffie-hellman-group14-sha1'],\r\n      cipher: ['aes256-cbc', 'aes192-cbc']},\r\n      username: remote_user,\r\n      password: remote_pass,\r\n      strictVendor: false,\r\n      debug: function ( string ) { console.log(string); }\r\n    });\r\n});\r\n```\r\n\r\nWe do have to specify the key and ciphers as the client's service is limited in it setup. Looking at where the error is being thrown from, it would seem to be a buffer overflow in a readString function.\r\n\r\n```\r\nDEBUG: Local ident: 'SSH-2.0-ssh2js0.1.9'\r\nDEBUG: Parser: IN_INIT\r\nDEBUG: Parser: IN_GREETING\r\nDEBUG: Parser: IN_HEADER\r\nDEBUG: Remote ident: 'SSH-2.0-Maverick_SSHD'\r\nDEBUG: Outgoing: Writing KEXINIT\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 8)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: pktLen:236,padLen:11,remainLen:232\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT\r\nDEBUG: Comparing KEXINITs ...\r\nDEBUG: (local) KEX algorithms: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1\r\nDEBUG: (remote) KEX algorithms: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1\r\nDEBUG: KEX algorithm: diffie-hellman-group1-sha1\r\nDEBUG: (local) Host key formats: ssh-rsa\r\nDEBUG: (remote) Host key formats: ssh-rsa\r\nDEBUG: Host key format: ssh-rsa\r\nDEBUG: (local) Client->Server ciphers: aes256-cbc,aes192-cbc\r\nDEBUG: (remote) Client->Server ciphers: aes256-cbc,aes192-cbc\r\nDEBUG: Client->Server Cipher: aes256-cbc\r\nDEBUG: (local) Server->Client ciphers: aes256-cbc,aes192-cbc\r\nDEBUG: (remote) Server->Client ciphers: aes256-cbc,aes192-cbc\r\nDEBUG: Server->Client Cipher: aes256-cbc\r\nDEBUG: (local) Client->Server HMAC algorithms: hmac-sha1-96\r\nDEBUG: (remote) Client->Server HMAC algorithms: hmac-sha1,hmac-sha1-96\r\nDEBUG: Client->Server HMAC algorithm: hmac-sha1-96\r\nDEBUG: (local) Server->Client HMAC algorithms: hmac-sha1-96\r\nDEBUG: (remote) Server->Client HMAC algorithms: hmac-sha1,hmac-sha1-96\r\nDEBUG: Server->Client HMAC algorithm: hmac-sha1-96\r\nDEBUG: (local) Client->Server compression algorithms: none,zlib@openssh.com,zlib\r\nDEBUG: (remote) Client->Server compression algorithms: none\r\nDEBUG: Client->Server compression algorithm: none\r\nDEBUG: (local) Server->Client compression algorithms: none,zlib@openssh.com,zlib\r\nDEBUG: (remote) Server->Client compression algorithms: none\r\nDEBUG: Server->Client compression algorithm: none\r\nDEBUG: Outgoing: Writing KEXDH_INIT\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 8)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: pktLen:700,padLen:10,remainLen:696\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXDH_REPLY\r\nDEBUG: Checking host key format\r\nDEBUG: Checking signature format\r\nDEBUG: Verifying host fingerprint\r\nDEBUG: Host accepted by default (no verification)\r\nDEBUG: Verifying signature\r\nDEBUG: Outgoing: Writing NEWKEYS\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 8)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: pktLen:12,padLen:10,remainLen:8\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: NEWKEYS\r\nDEBUG: Outgoing: Writing SERVICE_REQUEST (ssh-userauth)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:28,padLen:10,remainLen:16\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: SERVICE_ACCEPT\r\nDEBUG: Outgoing: Writing USERAUTH_REQUEST (password)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:12,padLen:10,remainLen:0\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_SUCCESS\r\n### Client :: Ready\r\nDEBUG: Outgoing: Writing CHANNEL_OPEN (0, session)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:28,padLen:10,remainLen:16\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_OPEN_CONFIRMATION\r\nDEBUG: Outgoing: Writing CHANNEL_REQUEST (0, subsystem: sftp)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:28,padLen:18,remainLen:16\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_WINDOW_ADJUST (0, 131072)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:12,padLen:6,remainLen:0\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_SUCCESS (0)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Outgoing: Writing CHANNEL_DATA (0)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:28,padLen:9,remainLen:16\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0)\r\n### SFTP session created\r\nDEBUG[SFTP]: Outgoing: Writing OPENDIR\r\nDEBUG: Outgoing: Writing CHANNEL_DATA (0)\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:44,padLen:6,remainLen:32\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: IGNORE\r\nDEBUG: Parser: IN_PACKETBEFORE (expecting 16)\r\nDEBUG: Parser: IN_PACKET\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: pktLen:140,padLen:12,remainLen:128\r\nDEBUG: Parser: IN_PACKETDATA\r\nDEBUG: Parser: Decrypting\r\nDEBUG: Parser: HMAC size:12\r\nDEBUG: Parser: IN_PACKETDATAVERIFY\r\nDEBUG: Parser: Verifying MAC\r\nDEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)\r\nDEBUG: Parser: IN_PACKETDATAAFTER, packet: CHANNEL_DATA (0)\r\nDEBUG[SFTP]: Parser: Response: STATUS\r\n[Error: SFTP session ended early]\r\n/Users/nickolas/Desktop/nickolas _ sftp-demo/app.js:100\r\n                  throw err;\r\n                        ^\r\nError: SFTP session ended early\r\n    at SFTPStream._cleanup (/Users/nickolas/Desktop/nickolas _ sftp-demo/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:193:17)\r\n    at readString (/Users/nickolas/Desktop/nickolas _ sftp-demo/node_modules/ssh2/node_modules/ssh2-streams/lib/utils.js:794:22)\r\n    at SFTPStream._transform (/Users/nickolas/Desktop/nickolas _ sftp-demo/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:373:26)\r\n    at SFTPStream.Transform._read [as __read] (_stream_transform.js:179:10)\r\n    at SFTPStream._read (/Users/nickolas/Desktop/nickolas _ sftp-demo/node_modules/ssh2/node_modules/ssh2-streams/lib/sftp.js:170:15)\r\n    at SFTPStream.Transform._write (_stream_transform.js:167:12)\r\n    at doWrite (_stream_writable.js:301:12)\r\n    at writeOrBuffer (_stream_writable.js:288:5)\r\n    at SFTPStream.Writable.write (_stream_writable.js:217:11)\r\n    at Channel.ondata (_stream_readable.js:540:20)\r\n```"},"comment":{"url":"https://api.github.com/repos/mscdex/ssh2/issues/comments/248510137","html_url":"https://github.com/mscdex/ssh2/issues/472#issuecomment-248510137","issue_url":"https://api.github.com/repos/mscdex/ssh2/issues/472","id":248510137,"user":{"login":"mscdex","id":54666,"avatar_url":"https://avatars.githubusercontent.com/u/54666?v=3","gravatar_id":"","url":"https://api.github.com/users/mscdex","html_url":"https://github.com/mscdex","followers_url":"https://api.github.com/users/mscdex/followers","following_url":"https://api.github.com/users/mscdex/following{/other_user}","gists_url":"https://api.github.com/users/mscdex/gists{/gist_id}","starred_url":"https://api.github.com/users/mscdex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mscdex/subscriptions","organizations_url":"https://api.github.com/users/mscdex/orgs","repos_url":"https://api.github.com/users/mscdex/repos","events_url":"https://api.github.com/users/mscdex/events{/privacy}","received_events_url":"https://api.github.com/users/mscdex/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T04:42:55Z","updated_at":"2016-09-21T04:42:55Z","body":"Either the language string size field in the packet is too large or the packet is too small. Assuming the ssh server is the Java Maverick SSH server, do you happen to know what version of the server this is so that I can try to replicate the issue to verify where the problem lies?"}}
{"actor":{"display_login":"mscdex"}}