console-rs / console

A rust console and terminal abstraction
MIT License
961 stars 113 forks source link

Add an assertion to `unix_term::read_bytes` to prevent reading past the end of a buffer #225

Open bmoxb opened 3 weeks ago

bmoxb commented 3 weeks ago

The (marked safe) read_bytes function makes a call to the unsafe function libc::read. If read_bytes were to be called with a count value larger than the length of buf, the call to libc::read would be undefined behaviour and unsafe. All current callsites of read_bytes appear OK, but adding an assertion would ensure that all possible calls to read_bytes will be safe. If you would prefer to avoid a runtime assertion, I would suggest marking read_bytes as unsafe instead.