taviso / 123elf

A native port of Lotus 1-2-3 to Linux.
1.18k stars 59 forks source link

Reimplementation of function at 0x80bb148 that prevents overflowing the destination buffer #104

Closed dbastone closed 2 years ago

dbastone commented 2 years ago

Fixes #103

This replaces the vulnerable function with a version that aborts the copy if the destination buffer is full.

Adding destination length checks within process_fmt()/fmt_cell_combine() isn't enough, because the vulnerable function can apply a form of run-length decoding based on the values in the source buffer (using memdup()). This can cause the destination buffer to expand beyond the size of the source buffer. The proof-of-concept exploit does this to overflow a 1024-byte buffer with a 38-byte file.

Replacing a function without a symbol was a bit tricky (and I'm not sure if this is the best way to handle it) but it seems to work and all of the tests pass. I won't be offended if you decide to go with an entirely different approach!