Ticket #4401: Segmentation fault in mcviewer.

* (mcview_growbuf_read_until): the previous call to mcview_show_error()
   invalidates sp by freeing view->ds_stdio_pipe. Reintroduce the check
   that was removed in a68f2d1202 but take
   sp's invalidity into account.

 * (mc_pclose): add a NULL pointer check to play safe.

Signed-off-by: Michael Schuster <michael@schuster.ms>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Michael Schuster 2022-08-19 13:35:20 +02:00 committed by Andrew Borodin
parent 0ef7237eea
commit a1f22e104d
2 changed files with 17 additions and 0 deletions

View File

@ -675,6 +675,13 @@ mc_pclose (mc_pipe_t * p, GError ** error)
{
int res;
if (p == NULL)
{
mc_replace_error (error, MC_PIPE_ERROR_READ, "%s",
_("Cannot close pipe descriptor (p == NULL)"));
return;
}
if (p->out.fd >= 0)
res = close (p->out.fd);
if (p->err.fd >= 0)

View File

@ -186,6 +186,16 @@ mcview_growbuf_read_until (WView * view, off_t ofs)
view->pipe_first_err_msg = FALSE;
mcview_show_error (view, sp->err.buf);
/* when switch from parse to raw mode and back,
* do not close the already closed pipe (see call to mcview_growbuf_done below).
* return from here since (sp == view->ds_stdio_pipe) would now be invalid.
* NOTE: this check was removed by ticket #4103 but the above call to
* mcview_show_error triggers the stdio pipe handle to be closed:
* mcview_close_datasource -> mcview_growbuf_done
*/
if (view->ds_stdio_pipe == NULL)
return;
}
if (sp->out.len > 0)