Skip to content

Unbounded strcpy(response, ...) in POST()/GET() HTTP client helpers #68

Description

@davidchatting-bot

Where

Two sites in `src/YoYoWiFiManager.cpp`, both flagged in source with `//#TODO: test length?`:

`POST(const char *server, const char *path, const char *payload, char *contentType, char *response)`:
```cpp
if(response && httpResponseCode > 0) {
//#TODO: test length?
strcpy(response, http.getString().c_str());
}
```

`GET(const char *server, const char *path, char *response)`:
```cpp
if (httpResponseCode > 0) {
//#TODO: test length?
strcpy(response, http.getString().c_str());
}
```

Problem

Both copy an HTTP response body of arbitrary length (from whatever peer/server was called) into a caller-supplied fixed-size `char *response` buffer with no length check - the same overflow shape as the `setCredentials()`/`onYoYoRequestPOST()` bugs fixed in #56/#57, just on the outgoing request path (a device calling another peer) rather than the incoming request path. Any caller passing a fixed-size stack/heap buffer as `response` is exposed to a heap/stack overflow if the remote peer's response is longer than expected.

Suggested fix

Either:

  • Take a `size_t responseSize` parameter at both call sites and bound the copy (`strncpy`/length check before copy, per the pattern used in the Heap buffer overflow: unbounded strcpy of untrusted JSON in setCredentials() #56 fix), or
  • Change the signature to take a `String&` instead of `char *`, avoiding the fixed-buffer assumption entirely (there's already a `GET(..., JsonDocument&)` overload that avoids this problem the same way).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions