unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pip Cet <pipcet@gmail.com>
Cc: 21380@debbugs.gnu.org
Subject: bug#21380: 25.0.50; GTK-induced segfault when scheduling timer from window-configuration-change-hook
Date: Mon, 31 Aug 2015 17:31:46 +0300	[thread overview]
Message-ID: <83a8t71qct.fsf@gnu.org> (raw)
In-Reply-To: <CAOqdjBf_BMvcSW3szDd+KJpGR90EzrVWv4QhYVxWyMoVOm_x=g@mail.gmail.com>

> Date: Sun, 30 Aug 2015 20:56:33 +0000
> From: Pip Cet <pipcet@gmail.com>
> Cc: 21380@debbugs.gnu.org
> 
>     Then all we have to do is block QUIT during that copy, no?
> 
> Yes for this particular segfault.

Can you show a patch that fixes the original segfault in your use
case?  I'm afraid I lost track, what with all the different scenarios
and potential solutions being thrown at this.  We should install the
fix, assuming it's clean.

> No* for similar segfaults that I think pose equally severe problems: if any other function calls concat/copy-sequence on data that is modified by window-configuration-change-hook, it should* still be possible to produce the segfault.

Emacs gives you enough rope to hang yourself; there's nothing new
here.  We should strive to protect the Emacs internals so that they
won't cause segfaults, but in user code any bets are off, and "don't
do that" is a valid response to whoever does such things.

> So it wouldn't even be safe for window-configuration-change-hook to add a timer to the timer list, because the outer frame might be in the middle of creating a copy of the timer list for some Lisp code that hasn't blocked input. (As in my example below)

Futzing with timers from within some hooks is indeed fundamentally
dangerous.  But we should still try to minimize the probability of a
crash, especially when it's Emacs itself who makes the offending copy,
because people do dangerous things all the time, and expect them to
work.  In this case, blocking input should do, I think.

> I really don't think QUIT should run any Lisp hooks, to be honest.

I don't think this limitation could fly.  It will disable a lot of
useful use patterns, and the outcry will be loud and clear.

> If I'm wrong and QUIT should be able to run Lisp hooks, concat needs to be fixed not to rely on its argument's size being unchanged after the make_sequence call.

That can't do any harm, so let's do it, too.

> *-I have been able to verify this segfault by interrupting the program at just the right time and resizing its X window then:
>  - gdb --args emacs -Q
>  - evaluate the following code:
> 
> (run-with-timer 0 1 #'ignore) ;; so the timer list isn't empty
> (add-hook 'window-configuration-change-hook (lambda () (run-with-timer 0 nil #'ignore)))

> (while t
>   (copy-sequence timer-list)
>   (accept-process-output nil 0)
>   )
> 
>  - interrupt and set a breakpoint with "b Fmake_sequence if !input_blocked_p()".
>  - wait for breakpoint to be hit, verify that concat's args[0] is equal to Vtimer_list.
>  - resize the X window
>  - continue in gdb
>  - segfault
> 
> As far as I can tell, that should be reproducible. Also as far as I can tell, it's merely a matter of luck that an X resize doesn't happen at the point where I interrupted the program to artificially trigger the segfault. However, I admit that it is a separate issue, less likely to occur in practice, and I'll open another bug for it if that's the way you prefer things.

But if input is blocked, as it would be in the case of copying
timer-list inside timer_check, the X events will not be acted upon,
and the problem will not happen, right?

IOW, the above situation is a case of a user shooting herself in the
foot by having that particular function in the hook and that
particular code that copies timer-list (which is an internal variable
unwise users should not touch).  Am I right?





  parent reply	other threads:[~2015-08-31 14:31 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-30 12:51 bug#21380: 25.0.50; GTK-induced segfault when scheduling timer from window-configuration-change-hook Pip Cet
2015-08-30 15:01 ` Eli Zaretskii
2015-08-30 15:24   ` Pip Cet
2015-08-30 15:27     ` Pip Cet
2015-08-30 16:24       ` Pip Cet
2015-08-30 18:10         ` martin rudalics
2015-08-30 18:20           ` Pip Cet
2015-08-30 19:50             ` Eli Zaretskii
2015-08-30 18:59           ` Pip Cet
2015-08-31  9:20             ` martin rudalics
2015-08-30 16:39     ` Eli Zaretskii
2015-08-30 16:42       ` Pip Cet
2015-08-30 19:44         ` Eli Zaretskii
2015-08-30 20:56           ` Pip Cet
2015-08-30 21:13             ` Pip Cet
2015-08-31 14:31             ` Eli Zaretskii [this message]
2015-09-01 10:20               ` Pip Cet
2015-09-01 15:03                 ` Eli Zaretskii
2015-09-01 15:22                   ` Pip Cet
2015-09-01 16:01                     ` Eli Zaretskii
2015-09-01 16:02                       ` Pip Cet
2015-09-01 16:23                         ` Eli Zaretskii
2015-09-02  7:02                       ` martin rudalics
2015-09-02 14:32                         ` Eli Zaretskii
2015-09-03 15:36                         ` Stefan Monnier
2015-09-05  7:38                           ` Eli Zaretskii
2015-09-05 15:18                             ` Stefan Monnier
2015-09-05 15:27                               ` Eli Zaretskii
2015-09-06 22:11                                 ` Stefan Monnier
2022-04-29 12:52                             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-29 13:40                               ` Eli Zaretskii
2022-04-29 13:44                                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-04-29 15:02                                   ` Pip Cet
2015-09-05 16:59                           ` Pip Cet
2015-09-06 22:22                             ` Stefan Monnier
2015-09-08 15:55                               ` Pip Cet
2015-09-01 15:14                 ` Pip Cet
2015-09-01 16:04                   ` Eli Zaretskii
2015-09-01 16:56                     ` Pip Cet
2015-09-01 17:19                       ` Eli Zaretskii
2015-09-01 20:48                         ` Pip Cet
2015-09-02 15:08                           ` Eli Zaretskii
2015-09-02 16:09                             ` Pip Cet
2015-09-02 19:13                               ` Eli Zaretskii
2015-09-02 22:08                                 ` Pip Cet
2020-09-07 17:07                           ` Lars Ingebrigtsen
2020-09-07 17:47                             ` Pip Cet
2020-09-07 19:09                             ` Eli Zaretskii
2020-09-08  9:57                               ` Lars Ingebrigtsen
2022-04-29 12:14                                 ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83a8t71qct.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=21380@debbugs.gnu.org \
    --cc=pipcet@gmail.com \
    /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.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).