troglobit / editline

A small replacement for GNU readline() for UNIX
https://troglobit.com/projects/editline/
Other
277 stars 56 forks source link

write_history silently eats IO errors in fprintf rather than failing #66

Open lf- opened 4 months ago

lf- commented 4 months ago

https://github.com/troglobit/editline/blob/c50d4c34d80a051ccb381301324cd3472902b363/src/editline.c#L1619-L1634

Note that fprintf has no check on its return value so it could fail without being reported. I am unsure if the IO errors turn the FILE * into some poison that would cause the fclose() to fail, but somehow I suspect they would not.

lf- commented 4 months ago

Also, the errno handling here completely violates the semantics of how readline does it: the return value should be 0 on success or errno on failure, and EOF is not a valid errno value. GNU readline by comparison does not guarantee that errno the global variable will not be clobbered on return, so the only way of getting its errno out is to look at the return value, but editline return value here is not always a valid errno.

The fix for that is to stop returning EOF and return errno there instead.

troglobit commented 4 months ago

The editline library is not intended to be a drop-in replacement for GNU readline. That being said, it's always a good idea to follow the principle of least surprise.

Pull requests are welcome that improve the stability and usability of the library.