poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fix invalid uses of siglongjmp


From: Bruno Haible
Subject: fix invalid uses of siglongjmp
Date: Sat, 27 Jun 2020 17:05:35 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; )

In pk-repl.c there are three cases of invalid siglongjmp invocations
(assuming a single-threaded poke). To reproduce one of them,
press Ctrl-D and then very quickly Ctrl-C. I see this:

  Type ".exit" to leave the program.
  (poke) 
  ^C
  (poke) .load gmo.pk
  /media/develdata/devel/inst-x86_64-64/share/poke/gmo.pk: Datei oder 
Verzeichnis nicht gefunden
  (poke) 
  *** stack smashing detected ***: ./poke/poke terminated
  Abgebrochen (Speicherabzug geschrieben)

The three cases are:
  (1) If the user presses Ctrl-C between the moment the signal handler
      is installed and the moment the first sigsetjmp is terminated.
  (2) If the user presses Ctrl-C between the moment a round of the REP loop
      is terminated and the next round of the REP loop is started.
  (3) If the user presses Ctrl-C after the function pk_repl has terminated.
      (This is the scenario above.)

In case (1) and (3), it is better for the program to behave like if no
handler was installed, that is, terminate the program.

In case (2), the user does not want to terminate poke; instead he wants
to (reliably!) get at the poke prompt again.

The attached proposed patch implements this. With it, I see this:

  Type ".exit" to leave the program.
  (poke) 
  ^C

A remark regarding the use of 'volatile': 'volatile' is needed for every
global variable that is accessed from a signal handler. (Think about the
main thread and the signal handler being executed on different CPUs.
Without 'volatile' and no memory barrier, the CPU that executes the main
thread might never propagate changes to the variable to the other CPUs.)
Unfortunately, I can't mark a sigjmpbuf variable as 'volatile' easily,
without introducing compilation warnings...

Bruno

Attachment: 0001-Fix-invalid-uses-of-siglongjmp.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]