@electerm/ssh2 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +2 -2
- package/lib/protocol/SFTP.js +12 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -244,7 +244,7 @@ class Client extends EventEmitter {
|
|
|
244
244
|
? cfg.debug
|
|
245
245
|
: undefined);
|
|
246
246
|
|
|
247
|
-
this.config.
|
|
247
|
+
this.config.encode = cfg.encode || 'utf8';
|
|
248
248
|
|
|
249
249
|
if (cfg.agentForward === true && !this.config.allowAgentFwd) {
|
|
250
250
|
throw new Error(
|
|
@@ -606,7 +606,7 @@ class Client extends EventEmitter {
|
|
|
606
606
|
};
|
|
607
607
|
const instance = (
|
|
608
608
|
isSFTP
|
|
609
|
-
? new SFTP(this, chanInfo, { debug, encoding: this.config.
|
|
609
|
+
? new SFTP(this, chanInfo, { debug, encoding: this.config.encode })
|
|
610
610
|
: new Channel(this, chanInfo)
|
|
611
611
|
);
|
|
612
612
|
this._chanMgr.update(info.recipient, instance);
|
package/lib/protocol/SFTP.js
CHANGED
|
@@ -115,6 +115,7 @@ const SERVER_VERSION_BUFFER = Buffer.from([
|
|
|
115
115
|
|
|
116
116
|
const RE_OPENSSH = /^SSH-2.0-(?:OpenSSH|dropbear)/;
|
|
117
117
|
const OPENSSH_MAX_PKT_LEN = 256 * 1024;
|
|
118
|
+
const IMPOSSIBLE_PKT_LEN = 10 * 1024 * 1024; // 10MB - if packet length is larger, it's likely garbage
|
|
118
119
|
|
|
119
120
|
const bufferParser = makeBufferParser();
|
|
120
121
|
|
|
@@ -218,6 +219,17 @@ class SFTP extends EventEmitter {
|
|
|
218
219
|
if (this._pktLen === 0)
|
|
219
220
|
return doFatalSFTPError(this, 'Invalid packet length');
|
|
220
221
|
if (this._pktLen > this._maxInPktLen) {
|
|
222
|
+
if (this._pktLen > IMPOSSIBLE_PKT_LEN) {
|
|
223
|
+
// Likely garbage data (e.g., text output from shell initialization)
|
|
224
|
+
// Reset parser state and continue
|
|
225
|
+
this._pktLenBytes = 0;
|
|
226
|
+
this._pktLen = 0;
|
|
227
|
+
this._pktPos = 0;
|
|
228
|
+
this._pktType = 0;
|
|
229
|
+
this._pktData = undefined;
|
|
230
|
+
this._pkt = undefined;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
221
233
|
const max = this._maxInPktLen;
|
|
222
234
|
return doFatalSFTPError(
|
|
223
235
|
this,
|
package/package.json
CHANGED