lichray / nvi2

A multibyte fork of the nvi editor for BSD
Other
144 stars 34 forks source link

use memmove to realign buffers #122

Closed brooksdavis closed 1 year ago

brooksdavis commented 1 year ago

Replace a rather convoluted realignment algorithm with memcpy(). In addition to being hard to understand, the code would read beyond the end of the input buffer in certain conditions (found on CheriBSD).

Sponsored by: DARPA

brooksdavis commented 1 year ago

I've not managed to figure out what the exact trigger is for the out of bounds read (I hit the error when editing over a laggy connections so not sure what state it was in), but I spent far too long staring at this code just to figure out what it was doing.

leres commented 1 year ago

I see that memcpy() handles overlap on FreeBSD but given that nvi2 is built on other operating systems wouldn't it be more conservative to use memmove()?

brooksdavis commented 1 year ago

Indeed, memmove is more correct.

lichray commented 1 year ago

I can't read the code, either. Thanks!