-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Bug in String::copy, out of bounds crash #9110
Comments
There are other functions which start to look 'odd' to me, but since they are there for so long, I start doubting myself if I'm seeing bugs everywhere.... For example: Arduino/cores/esp8266/WString.cpp Lines 209 to 227 in eda4e08
Line 222 I think setLen should be set to the minimum of oldLen and maxStrLen
And this one: Arduino/cores/esp8266/WString.cpp Lines 343 to 361 in eda4e08
Shouldn't
Or maybe the simplest fix might be to adapt
|
I'd suggest not, internals care about string length not internal representation aka cstring with null byte. Copies mentioning null should probably be considered a bug, delegating null byte handling to length setter. Meaning, we never try to do anything with it outside of length setter
...such as? |
I have not yet been able to log where it crashes, so I don't know exactly which string it crashes on. And I also did some testing here to see if my assumption about this is correct: size_t newSize = (maxStrLen + 16) & (~0xf); This always returns a So I think this should be put on hold till I found the true crash reason. Right now it seems like it might be a combination of a String copy where the string size has shrunk due to a few replace calls. It is in the assignment of a String to a
|
Can you point to the specific code & full stack dump w/ exc address etc.? My understanding this is related to the letscontrolit/ESPEasy#5013, but the original issue has neither |
This is while running on my PC, so probably not the same addresses.
My current work-around (stacktrace is not using this work-around as it doesn't crash anymore) is to not to use the I am looking into the String code to see if I can come up with some way to have either a String with a length longer than what is allocated, or a 0-character inbetween. |
If '\0' is embedded somewhere, there is an issue with replace() doing strlen() which probably does not do the right thing. Same with anything constructing / assigning using plain pointer |
In my test using ESPEasy, I do have a string which was 13 bytes and is reduced to some length less than 11 bytes. The reason I'm also thinking about a Anyway, I don't have conclusive example code yet and will try to get some sleep first as it has been a very busy day today. |
Basic Infos
Problem Description
See line 291 (and line 280):
Arduino/cores/esp8266/WString.cpp
Lines 284 to 293 in eda4e08
When allocating an array of N elements, accessing element
[N]
is out of bounds.This only happens sometimes at very specific string lengths, as
setLen
only allocates in multiples of N bytes.N.B. similar issue for ESP32, so I will also add an issue there.
Suggested fix:
N.B. This function is likely to be called with
strlen()
orstrlen_P()
as argument, which does not include the ending null character.The text was updated successfully, but these errors were encountered: