Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scapy/layers/tftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def BEGIN(self):
self.my_tid = self.sport or RandShort()._fix()
bind_bottom_up(UDP, TFTP, dport=self.my_tid)
self.server_tid = None
self.res = b""
self.res = bytearray()

self.l3 = IP(dst=self.server) / UDP(sport=self.my_tid, dport=self.port) / TFTP() # noqa: E501
self.last_packet = self.l3 / TFTP_RRQ(filename=self.filename, mode="octet") # noqa: E501
Expand Down Expand Up @@ -243,7 +243,7 @@ def ERROR(self, pkt):
@ATMT.state(final=1)
def END(self):
split_bottom_up(UDP, TFTP, dport=self.my_tid)
return self.res
return bytes(self.res)


class TFTP_write(Automaton):
Expand Down
22 changes: 22 additions & 0 deletions test/scapy/layers/tftp.uts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ tftp_read = TFTP_read("file.txt", "1.2.3.4", sport=0x2807,
res = tftp_read.run()
assert res == (b"P" * 512 + b"<3")

= TFTP_read extends one response buffer after the first block
from scapy.automaton import ATMT
from scapy.layers.tftp import TFTP_read
from scapy.packet import Raw

client = object.__new__(TFTP_read)
client.res = bytearray()
client.awaiting = 1
client.blocksize = 512

def receive_full_block():
try:
TFTP_read.RECEIVING.atmt_origfunc(client, Raw(b"A" * 512))
except ATMT.NewStateRequested:
pass

receive_full_block()
receive_full_block()
response_buffer = client.res
receive_full_block()
assert client.res is response_buffer

= TFTP_read() automaton error
~ linux

Expand Down
Loading