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

[Bugreport] Misuse of vector.resize in Request.resize() #119

Open
vrqq opened this issue Aug 6, 2019 · 3 comments
Open

[Bugreport] Misuse of vector.resize in Request.resize() #119

vrqq opened this issue Aug 6, 2019 · 3 comments

Comments

@vrqq
Copy link
Contributor

vrqq commented Aug 6, 2019

void resize(size_t size) {
copy_method_url();
buf_.resize(size);
}

I saw a lot of reference on the pointer request.buf_.data() in source code.
But you also use vector.resize() here, that may cause memory reallocation.

( ̄▽ ̄")

@qicosmos
Copy link
Owner

qicosmos commented Aug 7, 2019

在resize之前已经把需要拷贝出来的东西都拷贝了。

@vrqq
Copy link
Contributor Author

vrqq commented Aug 7, 2019

READ of size 1 at 0x61d00000fabe thread T6
    #0 0x761da6 in cinatra::iequal(char const*, unsigned long, char const*) 
    #1 0x778459 in cinatra::request::get_header_value(std::basic_string_view<char, std::char_traits<char> >) const
    #2 ......
SUMMARY: AddressSanitizer: heap-use-after-free in cinatra::iequal(char const*, unsigned long, char const*)

header_len_ = phr_parse_request(buf_.data(), cur_size_, &method_,
&method_len_, &url_, &url_len_,
&minor_version_, headers_, &num_headers_, last_len);

You may forgot that struct phr_header headers_[32];

@qicosmos
Copy link
Owner

qicosmos commented Aug 9, 2019

谢谢你指出这个问题,我已经增加了拷贝header了,可以保证resize的时候信息不会丢掉。

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