1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00
Arduino/hardware/arduino/avr
Matthijs Kooijman 2068f88a21 Fix bounds check in String::remove()
Previously, if you passed in a very big index and/or count, the
`index + count` could overflow, making the count be used as-is instead
of being truncated (causing the string to be updated wrongly and
potentially writing to arbitrary memory locations).

We can rewrite the comparison to use `len - index` instead. Since we
know that index < len, we are sure this subtraction does not overflow,
regardless of what values of index and count we pass in.

As an added bonus, the `len - index` value already needed be calculated
inside the if, so this saves a few instructions in the generated code.

To illustrate this problem, consider this code:

String foo = "foo";
Serial.println(foo.length()); // Prints 3
foo.remove(1, 65535); // Should remove all but first character
Serial.println(foo.length()); // Prints 4 without this patch

Not shown in this is example is that some arbitrary memory is written
as well.
2014-09-10 12:33:25 +02:00
..
bootloaders merge 2013-10-14 12:42:42 +02:00
cores/arduino Fix bounds check in String::remove() 2014-09-10 12:33:25 +02:00
firmwares added support for the ArduinoISP 2014-07-02 15:03:12 +02:00
libraries SPI Transactions for AVR 2014-08-01 05:38:27 -07:00
variants Merge branch 'master' into ide-1.5.x 2014-02-12 17:17:33 +01:00
boards.txt Arduino Pro and Pro Mini should use eightanaloginputs variant, so all 8 analog pins can be used 2014-06-28 22:37:26 +02:00
platform.txt Correct implementation of gcc specific internal functions 2014-09-06 12:42:25 +02:00
programmers.txt added support for the ArduinoISP 2014-07-02 15:03:12 +02:00