Skip to content

Commit 236fb08

Browse files
committed
w/a: allow invalid OACK; fixes msoulier#136
mobaxterm sends OACK with multiple trailing nullbytes; this looks like (and should be parsed as) null-length options, which is invalid the workaround is to strip superfluous trailing nullbytes this has the potential side-effect of masking similar server bugs (for example a lone option name without a value), but the warning should make this apparent
1 parent 0087f02 commit 236fb08

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

partftpy/TftpPacketTypes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ def decode_options(self, buffer):
3737
values."""
3838

3939
log.debug("decode_options: buffer is %d bytes: %r", len(buffer), buffer)
40+
41+
if buffer.endswith(b"\x00\x00"):
42+
log.warn(
43+
"Received an invalid OACK (multiple trailing nullbytes); will workaround: %r",
44+
buffer,
45+
)
46+
buffer = buffer.rstrip(b"\x00") + b"\x00"
47+
if len(buffer.split(b"\x00")) % 2 == 0:
48+
# the last \x00 was an option with no value; support that quirk as well
49+
buffer += b"\x00"
50+
4051
words = [x.decode("utf-8", "replace") for x in buffer.split(b"\x00")]
4152
if not words:
4253
log.debug("client provided no options")

0 commit comments

Comments
 (0)