zsh-workers
 help / color / mirror / code / Atom feed
From: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
To: zsh-workers@zsh.org
Subject: zsh signal handler is not safe
Date: Wed, 22 May 2019 23:26:43 -0700	[thread overview]
Message-ID: <EACB4651-7692-42DD-B5EB-17083CDE11A3@apple.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 902 bytes --]

Hi folks,

I wanted to reach out to you and let you know that I've seen some crashes in zsh related to using illegal API from within a signal handler context.  Specifically, you signal handler zhandle() will call zexit() with which in turn calls savehistfile() and lockhistfile() which expectedly does a lot of API calls that are not thread safe (eg: malloc/stdio/etc).

It looks like zexit()'s from_where is set to 1 for the signal handler case, which is causing HFILE_NO_REWRITE to be added to the writeflags passed to savehistfile().  That seems to be designed to avoid the memory allocations from reading in the existing file, but unfortunately we still fail in the call to lockhistfile().

It would be better for your signal handler to set a sentinel that will be checked by the main event loop to trigger the exit and then just get out of the signal handler as soon as possible.

--Jeremy

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3433 bytes --]

                 reply	other threads:[~2019-05-23  6:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=EACB4651-7692-42DD-B5EB-17083CDE11A3@apple.com \
    --to=jeremyhu@apple.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).