From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23621 invoked by alias); 10 Aug 2015 00:29:47 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36033 Received: (qmail 20264 invoked from network); 10 Aug 2015 00:29:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=WqeYXCJxuFvQZu8Haco52sC00lAuSKBtRLw7jYmgX5U=; b=Lue+rlxp3lzsUiVOOayI2RgwKG7r13pWKyp4oDrSLihg+fBQ2dsQKGw9oMCULSDiwz 6iXoZWTIDApRsJwdugJrUo9o7YtjCDQkTxYJ5Ih8eHlkTqxfDZb0BR3d+fmtL842vudF 1O8OxqJLQssUImTqHpJYup2A247rrQCvBiwj1zGvmUv0rYhKQAAQXidSfieofrRGIs93 OIs5j69Qvx0XAF6zzrCKbjikpyT5VG/T1MMA0wFejuBBMuByzGGJEPL2y1uoOatfzUGf siQZR/LPzPLD2Op3e8rbF/Plxten0iRxomsjCCt7ndCKbw2e8gqFtHdglW4bUgQDwOdp bKPQ== X-Gm-Message-State: ALoCoQkzJs1rAnT2d2c7BcoHiD5RUi5TOKqJUaix1Avg7jJG938wG5Q4JZNrWsM/D1v+7ZjFF9uY X-Received: by 10.182.40.165 with SMTP id y5mr16907939obk.21.1439166585225; Sun, 09 Aug 2015 17:29:45 -0700 (PDT) From: Bart Schaefer Message-Id: <150809172942.ZM4190@torch.brasslantern.com> Date: Sun, 9 Aug 2015 17:29:42 -0700 In-Reply-To: <150809164225.ZM10049@torch.brasslantern.com> Comments: In reply to Bart Schaefer "Re: Deadlock when receiving kill-signal from child process" (Aug 9, 4:42pm) References: <150803085228.ZM24837@torch.brasslantern.com> <150803135818.ZM24977@torch.brasslantern.com> <150804235400.ZM9958@torch.brasslantern.com> <150805085258.ZM17673@torch.brasslantern.com> <150805115249.ZM7158@torch.brasslantern.com> <150805132014.ZM7746@torch.brasslantern.com> <150805220656.ZM18545@torch.brasslantern.com> <150806085451.ZM402@torch.brasslantern.com> <150806223906.ZM17762@torch.brasslantern.com> <150809164225.ZM10049@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Deadlock when receiving kill-signal from child process MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Aug 9, 4:42pm, Bart Schaefer wrote: } } Nevertheless, it looks like glob.c needs to protect some places where } it manipulates global state. I couldn't really find anything definitive -- all the memory management routines (halloc, zhalloc, zfree, etc.) already do signal queuing, so we only get into trouble with e.g. stdio using the library malloc/free directly. The hunks in patcompile() below are paranoia because the static globals patcode, patsize, et al. are being frobbed -- but even with this I get worried that a signal trap that uses pattern matching called in the midst of some other pattern matching operation could leave those in an inconsistent state, because they're not saved/restored like globbing state in zglob(). Similarly if you were in the middle of a pattern that wanted to set the MATCH / MBEGIN / MEND / match / mbegin / mend parameters and then a trap handler also did so, it sure looks to me as if the state of those parameters becomes indeterminate. Patch below follows on to 36022 but doesn't overlap with it in any way. diff --git a/Src/glob.c b/Src/glob.c index eff34a2..f82c3bd 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -216,22 +216,26 @@ static struct globdata curglobdata; #define save_globstate(N) \ do { \ + queue_signals(); \ memcpy(&(N), &curglobdata, sizeof(struct globdata)); \ (N).gd_pathpos = pathpos; \ (N).gd_pathbuf = pathbuf; \ (N).gd_glob_pre = glob_pre; \ (N).gd_glob_suf = glob_suf; \ pathbuf = NULL; \ + unqueue_signals(); \ } while (0) #define restore_globstate(N) \ do { \ + queue_signals(); \ zfree(pathbuf, pathbufsz); \ memcpy(&curglobdata, &(N), sizeof(struct globdata)); \ pathpos = (N).gd_pathpos; \ pathbuf = (N).gd_pathbuf; \ glob_pre = (N).gd_glob_pre; \ glob_suf = (N).gd_glob_suf; \ + unqueue_signals(); \ } while (0) /* pathname component in filename patterns */ diff --git a/Src/pattern.c b/Src/pattern.c index 8fa1a72..7d38988 100644 --- a/Src/pattern.c +++ b/Src/pattern.c @@ -520,6 +520,8 @@ patcompile(char *exp, int inflags, char **endexp) char *lng, *strp = NULL; Patprog p; + queue_signals(); + startoff = sizeof(struct patprog); /* Ensure alignment of start of program string */ startoff = (startoff + sizeof(union upat) - 1) & ~(sizeof(union upat) - 1); @@ -582,8 +584,10 @@ patcompile(char *exp, int inflags, char **endexp) if (!strp || (*strp && *strp != '/')) { /* No, do normal compilation. */ strp = NULL; - if (patcompswitch(0, &flags) == 0) + if (patcompswitch(0, &flags) == 0) { + unqueue_signals(); return NULL; + } } else { /* * Yes, copy the string, and skip compilation altogether. @@ -715,6 +719,8 @@ patcompile(char *exp, int inflags, char **endexp) if (endexp) *endexp = patparse; + + unqueue_signals(); return p; } -- Barton E. Schaefer