edward0429 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Memory corruption in String::replace #694

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. String hello = "hello";
2. hello.replace("hello","hello, world");

What is the expected output? What do you see instead?
This causes random memory to get overwritten.  replace() will call 
lastIndexOf() with an index of -1.  but since lastIndexOf() takes an UNSIGNED 
as the 2nd parameter, MAXINT is actually passed, and chaos ensues.

What version of the Arduino software are you using?
git head

Please provide any additional information below.
Attached a patch which is one possible way of solving it.

Original issue reported on code.google.com by maniac...@ymail.com on 24 Oct 2011 at 4:02

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report and fix!

https://github.com/arduino/Arduino/commit/d9f9676d23c7430f0cc31e10641861013b9a17
04

Original comment by dmel...@gmail.com on 25 Oct 2011 at 3:16