1*5a6e8488SAndroid Build Coastguard Worker# Memory Bugs 2*5a6e8488SAndroid Build Coastguard Worker 3*5a6e8488SAndroid Build Coastguard WorkerThis is a list of all of the memory bugs that were found in *released* versions 4*5a6e8488SAndroid Build Coastguard Workerof `bc`, `dc`, or `bcl`. (Non-released commits with memory bugs do not count.) 5*5a6e8488SAndroid Build Coastguard Worker 6*5a6e8488SAndroid Build Coastguard WorkerI made this list for two reasons: first, so users can know what versions of 7*5a6e8488SAndroid Build Coastguard Worker`bc`, `dc`, and `bcl` have vulnerabilities, and two, I once had a perfect record 8*5a6e8488SAndroid Build Coastguard Workerand then found a couple, but forgot and claimed I still had a perfect record 9*5a6e8488SAndroid Build Coastguard Workerright after, which was embarrassing. 10*5a6e8488SAndroid Build Coastguard Worker 11*5a6e8488SAndroid Build Coastguard WorkerThis list is sorted by the first version a bug exists in, not the last it 12*5a6e8488SAndroid Build Coastguard Workerexisted in. 13*5a6e8488SAndroid Build Coastguard Worker 14*5a6e8488SAndroid Build Coastguard Worker* In versions `1.1.0` until `6.2.0` (inclusive) of `bc` and `dc`, there is a 15*5a6e8488SAndroid Build Coastguard Worker out of bounds read and write in history when pressing ctrl+r (or any other 16*5a6e8488SAndroid Build Coastguard Worker unused letter) then inserting two characters. 17*5a6e8488SAndroid Build Coastguard Worker 18*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.2.1`. 19*5a6e8488SAndroid Build Coastguard Worker 20*5a6e8488SAndroid Build Coastguard Worker* In versions `3.0.0` until `6.0.1` (inclusive) of `bc` and `dc`, there is a 21*5a6e8488SAndroid Build Coastguard Worker double-free on `SIGINT` when using command-line expressions with `-e` and 22*5a6e8488SAndroid Build Coastguard Worker `-f`. This was caused by not properly ending a jump series. 23*5a6e8488SAndroid Build Coastguard Worker 24*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.0.2`. 25*5a6e8488SAndroid Build Coastguard Worker 26*5a6e8488SAndroid Build Coastguard Worker* In versions `3.0.0` until `6.7.5` (inclusive) of `bc` and `dc`, there is a 27*5a6e8488SAndroid Build Coastguard Worker possible out-of-bounds read when there is an error flushing `stdout` on exit 28*5a6e8488SAndroid Build Coastguard Worker because such an error would cause `bc` and `dc` to attempt to use a `jmp_buf` 29*5a6e8488SAndroid Build Coastguard Worker when none exists. 30*5a6e8488SAndroid Build Coastguard Worker 31*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.7.6`. 32*5a6e8488SAndroid Build Coastguard Worker 33*5a6e8488SAndroid Build Coastguard Worker* In versions `5.0.0` until `6.0.4` (inclusive) of `bc`, there is an 34*5a6e8488SAndroid Build Coastguard Worker out-of-bounds access if a non-local (non-`auto`) variable is set to a string 35*5a6e8488SAndroid Build Coastguard Worker with `asciify()`, then the function is redefined with a use of the same 36*5a6e8488SAndroid Build Coastguard Worker non-local variable. 37*5a6e8488SAndroid Build Coastguard Worker 38*5a6e8488SAndroid Build Coastguard Worker This happened because strings were stored per-function, and the non-local 39*5a6e8488SAndroid Build Coastguard Worker variable now had a reference to the string in the old function, which could be 40*5a6e8488SAndroid Build Coastguard Worker at a higher index than exists in the new function. Strings are stored globally 41*5a6e8488SAndroid Build Coastguard Worker now, and they are *not* freed once not used. 42*5a6e8488SAndroid Build Coastguard Worker 43*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.1.0`. 44*5a6e8488SAndroid Build Coastguard Worker 45*5a6e8488SAndroid Build Coastguard Worker* In versions `5.0.0` until `6.0.4` (inclusive) of `bc`, there is another 46*5a6e8488SAndroid Build Coastguard Worker out-of-bounds access if an array is passed to the `asciify()` built-in 47*5a6e8488SAndroid Build Coastguard Worker function as the only argument. This happened because arrays are allowed as 48*5a6e8488SAndroid Build Coastguard Worker function arguments, which allowed them to be used as arguments to `asciify()`, 49*5a6e8488SAndroid Build Coastguard Worker but they should not have been allowed. However, since they were, the 50*5a6e8488SAndroid Build Coastguard Worker `asciify()` code tried to access an argument that was not there. 51*5a6e8488SAndroid Build Coastguard Worker 52*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.1.0`. 53*5a6e8488SAndroid Build Coastguard Worker 54*5a6e8488SAndroid Build Coastguard Worker* In version `6.0.0` of `bcl`, there are several uses of initialized data that 55*5a6e8488SAndroid Build Coastguard Worker have the same root cause: I forgot to call `memset()` on the per-thread global 56*5a6e8488SAndroid Build Coastguard Worker data. This is because the data used to be *actually* global, which meant that 57*5a6e8488SAndroid Build Coastguard Worker it was initialized to zero by the system. This happened because I thought I 58*5a6e8488SAndroid Build Coastguard Worker had properly hooked Valgrind into my `bcl` tests, but I had not. 59*5a6e8488SAndroid Build Coastguard Worker 60*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.0.1`. 61*5a6e8488SAndroid Build Coastguard Worker 62*5a6e8488SAndroid Build Coastguard Worker* In version `6.0.0` until `6.2.4` (inclusive) of `bcl`, there is a possible 63*5a6e8488SAndroid Build Coastguard Worker use-after-free if `bcl_init()` fails. 64*5a6e8488SAndroid Build Coastguard Worker 65*5a6e8488SAndroid Build Coastguard Worker The first version without this bug is `6.2.5`. 66