Skip to content

Buffer length check in socket_write() #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bjnhur opened this issue Aug 3, 2021 · 2 comments
Closed

Buffer length check in socket_write() #41

bjnhur opened this issue Aug 3, 2021 · 2 comments

Comments

@bjnhur
Copy link
Contributor

bjnhur commented Aug 3, 2021

I think, I found a bug in adafruit_wiznet5k/adafruit_wiznet5k.py

line 724, the code already has ret variable (SOCK_SIZE check & len of buffer)

if len(buffer) > SOCK_SIZE:
ret = SOCK_SIZE
else:
ret = len(buffer)

But, line 747, 751, didn't use this ret variable.

ptr = (ptr + len(buffer)) & 0xFFFF
self._write_sntx_wr(socket_num, ptr)
cntl_byte = 0x14 + (socket_num << 5)
self.write(dst_addr, cntl_byte, buffer)

Need to fix? My suggestion is:

        # update sn_tx_wr to the value + data size
        ptr = (ptr + ret) & 0xFFFF # <-- use ret
        self._write_sntx_wr(socket_num, ptr)

        cntl_byte = 0x14 + (socket_num << 5)
        txbuf = buffer[:ret] # <- use ret
        self.write(dst_addr, cntl_byte, txbuf) # <- use txbuf
@brentru
Copy link
Member

brentru commented Aug 4, 2021

@bjnhur Would you be interested in opening a pull request? I'll take a look if you tag me.

@tekktrik
Copy link
Member

Resolved by #42 with suggested fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants