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 overlapping memcpy call in String::trim #4938

Merged
merged 2 commits into from
Jul 19, 2018

Conversation

earlephilhower
Copy link
Collaborator

memcpy() is undefined when source and destination overlap. String::trim
uses it when shifting the string left to remove left padding.

Replace with memmove() which is always safe, even when overlapped.

memcpy() is undefined when source and destination overlap.  String::trim
uses it when shifting the string left to remove left padding.

Replace with memmove() which is always safe, even when overlapped.
@earlephilhower
Copy link
Collaborator Author

earlephilhower commented Jul 18, 2018

Same kind of error as seen in ::remove, overlapping source and dest (this is from an add'l host test started locally but not pushed yet):

==19180== 1 errors in context 1 of 1:
==19180== Source and destination overlap in memcpy(0x5bb9f60, 0x5bb9f64, 7)
==19180==    at 0x4C32513: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19180==    by 0x4BC705: String::trim() (WString.cpp:756)
==19180==    by 0x41AC2D: ____C_A_T_C_H____T_E_S_T____20() (test_string.cpp:24)
==19180==    by 0x44B135: Catch::FreeFunctionTestCase::invoke() const (catch.hpp:5874)
==19180==    by 0x4206C2: Catch::TestCase::invoke() const (catch.hpp:6779)
==19180==    by 0x446677: Catch::RunContext::invokeActiveTestCase() (catch.hpp:5473)
==19180==    by 0x445EB5: Catch::RunContext::runCurrentTest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) (catch.hpp:5445)
==19180==    by 0x4432AD: Catch::RunContext::runTest(Catch::TestCase const&) (catch.hpp:5284)
==19180==    by 0x447521: Catch::Runner::runTests() (catch.hpp:5603)
==19180==    by 0x449B3A: Catch::Session::run() (catch.hpp:5734)
==19180==    by 0x44988D: Catch::Session::run(int, char* const*) (catch.hpp:5714)
==19180==    by 0x42B887: main (catch.hpp:9278)
==19180==
==19180== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

@earlephilhower earlephilhower merged commit 63ab79e into esp8266:master Jul 19, 2018
@earlephilhower earlephilhower deleted the stringfix branch July 19, 2018 01:36
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.

1 participant