Skip to content
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

Fix potential socket data read already into self._buffer #185

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

us3r64
Copy link
Contributor

@us3r64 us3r64 commented Jan 15, 2024

Fixes #186

@dhalbert dhalbert linked an issue Jan 15, 2024 that may be closed by this pull request
@@ -113,6 +113,19 @@ def recv_into(self, buffer, nbytes: int = 0):
num_to_read = len(buffer) if nbytes == 0 else nbytes
num_read = 0
while num_to_read > 0:
# we might have read socket data into the self._buffer with:
# esp32spi_wsgiserver: socket_readline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discarded esp32spi_wsigiserver. Are there other circumstances where is could happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked any other libraries where _buffer is used, only https://github.com/adafruit/Adafruit_CircuitPython_WSGI/blob/main/adafruit_wsgi/esp32spi_wsgiserver.py

But i think is kinda of expected behavior and reasonable to use the _buffer, read as much as possible from the socket, because is not performant to read one bit at a time to find EOL for example.

This implementation also made into Adafruit_CircuitPython_Wiznet5k, adafruit_wiznet5k_socket _readline and adafruit_wiznet5k_wsgiserver so maybe is spread.

@dhalbert dhalbert merged commit 0adb75b into adafruit:main Jan 15, 2024
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 16, 2024
Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 6.1.3 from 6.1.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#185 from us3r64/fix/recv_into-self-_buffer
  > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#183 from us3r64/fix/socket-recv_into

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
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

Successfully merging this pull request may close these issues.

Fix WSGI headers parse and readline implementation
2 participants