Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.
This repository was archived by the owner on Jun 18, 2025. It is now read-only.

3rd argument in memcpy. #4

@mikeliaohm

Description

@mikeliaohm

Hi, thank you for the great work.

I've encountered a seg fault after registering a new uri. The issue seems to related to memcpy of response_string. I think the 3rd argument should be the size of the response string to be copied instead of kMaxBufferSize, or whichever is smaller.

response_string =
to_string(http_response, http_request.method() != HttpMethod::HEAD);
memcpy(raw_response->buffer, response_string.c_str(), kMaxBufferSize);
raw_response->length = response_string.length();
}

this is a potential fix.

  response_string
      = to_string (http_response, http_request.method () != HttpMethod::HEAD);
  const size_t res_len = response_string.length ();
  size_t len_to_copy = (res_len < kMaxBufferSize) 
    ? res_len : kMaxBufferSize;

  memmove (raw_response->buffer, response_string.c_str (), len_to_copy);
  
  raw_response->buffer[response_string.length ()] = '\0';
  raw_response->length = response_string.length ();

I've forked the project to reproduce my error at this repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions