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

HttpClient buffer too small #38

Open
Michele31415 opened this issue Apr 6, 2017 · 1 comment
Open

HttpClient buffer too small #38

Michele31415 opened this issue Apr 6, 2017 · 1 comment

Comments

@Michele31415
Copy link

In HttpClient.h, the value of buffer is only 1024. This is pretty small and means that URL's longer than a few hundred characters are truncated. I'd love to see this number increased to say, 8192. Or expose it so the user can select a value that meets their needs.

@ScruffR
Copy link

ScruffR commented Dec 12, 2019

Additionally to that I do see a potential buffer overflow issue with this code

        while (client.available()) {
            ...
            if (bufferPosition < sizeof(buffer)-1) {
                buffer[bufferPosition] = c;
            } else if ((bufferPosition == sizeof(buffer)-1)) {
                buffer[bufferPosition] = '\0'; // Null-terminate buffer
                client.stop();
                error = true;

                #ifdef LOGGING
                Serial.println("HttpClient>\tError: Response body larger than buffer.");
                #endif
            }
            bufferPosition++;
        }
        buffer[bufferPosition] = '\0'; // Null-terminate buffer

In case of a response greater or equal to sizeof(buffer) the final bufferPosition++ will increment to sizeof(buffer) and the following buffer[bufferPosition] = '\0' will actually end up in the byte following the actual buffer.

There actually should be a break inside the else if() branch to avoid the additional increment (and the zero-termination inside that branch can be omitted due to the same instruction following the loop.

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

2 participants