Skip to content

EEPROMClass readString Bug #1252

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

Closed
michygit opened this issue Mar 23, 2018 · 2 comments · Fixed by #2439
Closed

EEPROMClass readString Bug #1252

michygit opened this issue Mar 23, 2018 · 2 comments · Fixed by #2439

Comments

@michygit
Copy link

Hi! Is this bug?

String EEPROMClass::readString (int address)
{
if (address < 0 || address > _size)
return String(0);

uint16_t len;
for (len = 0; len <= _size; len++)
if (_data[address + len] == 0)
break;

if (address + len > _size)
return String(0);

char value[len + 1];
memcpy((uint8_t*) value, _data + address, len);
value[len + 1] = 0; <- ????
return String(value);
}

@rousir
Copy link

rousir commented Mar 24, 2018

String terminator 0x00

@jasonhillier
Copy link

jasonhillier commented Jun 30, 2018

bump

I was having an issue with EEPROM.readString() always putting an extra junk byte at the end. It looks like this is a bug!

Specifically, these lines:
Assume len=10, then

char value[len + 1]; //SIZE is 11
memcpy((uint8_t*) value, _data + address, len); //we READ 10 bytes
value[len + 1] = 0; <- //WAIT! we are writing the null terminator at index 11!, 
//that is the 12th byte in the array! We are writing out-of-bounds of the array! this means value[len]=? //because it is a byte from random memory!

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 a pull request may close this issue.

3 participants