diff options
author | Robey Pointer <robey@lag.net> | 2006-12-15 13:19:36 -0800 |
---|---|---|
committer | Robey Pointer <robey@lag.net> | 2006-12-15 13:19:36 -0800 |
commit | 7058f5ead235ce5650d4b9d8997a6901e68bc7da (patch) | |
tree | 1b39cc51b2f7831a5d6d35e13242314209ac42fc | |
parent | 76285309cf57f5be12e6ac066c53393e382cf1d5 (diff) |
[project @ robey@lag.net-20061215211936-rgc3uzy5ai9h6qho]
bug 75370: notice garbage sftp packets
since sftp packets shouldn't be larger than about 32k, if the first length
byte is non-zero (ie, the packet size > 16M), raise an exception.
-rw-r--r-- | paramiko/sftp.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/paramiko/sftp.py b/paramiko/sftp.py index 0b2bbe29..8047c4a2 100644 --- a/paramiko/sftp.py +++ b/paramiko/sftp.py @@ -176,7 +176,12 @@ class BaseSFTP (object): self._write_all(out) def _read_packet(self): - size = struct.unpack('>I', self._read_all(4))[0] + x = self._read_all(4) + # most sftp servers won't accept packets larger than about 32k, so + # anything with the high byte set (> 16MB) is just garbage. + if x[0] != '\x00': + raise SFTPError('Garbage packet received') + size = struct.unpack('>I', x)[0] data = self._read_all(size) if self.ultra_debug: self._log(DEBUG, util.format_binary(data, 'IN: ')); |