Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH crashed when reading bytes from a large binary



On Mon, Sep 12, 2022 at 12:37 AM Jun T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>
> > 2022/09/11 23:43, Liu, Song <songliu@xxxxxxx> wrote:
> >
> > The problem is that, when ZSH failed to reallocate memory, ZSH didn’t check the return value of `realloc` function and handle the error. This will make ZSH crash.
>
> There are many other places where the return value of realloc() is not checked.
> Can we simply replace them by zrealloc()?

Replacing them with zrealloc() will still result in immediate exit of
the shell, just with a different error message and no stack trace.

> > } else {
> > free(buf);
> > return EXIT_FAILURE;
> > }

The specific question here is whether having the "read" builtin return
failure at this point will allow the shell to recover from the
out-of-memory state, or whether it's just delaying the inevitable
death.  (Aside, we use EXIT_FAILURE exactly nowhere, so if we do not
exit, this should just be "return 1" as if end-of-file was encountered
per docs.)

In most cases we've assumed that once the shell is out of memory,
there's no way back, so how it dies is not that interesting.




Messages sorted by: Reverse Date, Date, Thread, Author