unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Jan Nieuwenhuizen <janneke@gnu.org>
Cc: guix-devel@gnu.org, bug-hurd@gnu.org
Subject: raise(-1) succeeds for programs linked against libpthread
Date: Tue, 13 Oct 2020 15:41:37 +0200	[thread overview]
Message-ID: <87h7qyjl9q.fsf_-_@gnu.org> (raw)
In-Reply-To: <87tuuzd6aq.fsf@gnu.org> (Jan Nieuwenhuizen's message of "Mon, 12 Oct 2020 13:37:01 +0200")

Hi!

(Cc: bug-hurd.)

Jan Nieuwenhuizen <janneke@gnu.org> skribis:

>>> #include <signal.h>
>>>
>>> int
>>> main (void)
>>> {
>>>   if (!raise (-1))
>>>     return 1;
>>>   
>>>   return 0;
>>> }
>>
>> I don’t know if it’s relevant here, but you should always use ‘-pthread’
>> both at compile time and link time:
>>
>>   gcc raise.c -pthread
>>
>> That typically defines a few macros that may or may not have an effect
>> on the code at hand.
>
> Ah...right.  Makes no difference, though:
>
> root@childhurd ~# guix environment --bootstrap --ad-hoc gcc-toolchain@7
> root@childhurd ~ [env]# gcc raise.c
> root@childhurd ~ [env]# ./a.out
> root@childhurd ~ [env]# echo $?
> 0
> root@childhurd ~ [env]# gcc raise.c -pthread
> root@childhurd ~ [env]# ./a.out
> User defined signal 2

Interesting!  In the second case, we’re using ‘__pthread_kill’ from
‘pt-kill.c’ (instead of ‘kill’).

The expected behavior is that ‘raise’ should return non-zero and EINVAL.

‘pthread_kill’ passes the signal number to ‘_hurd_raise_signal’, which
assumes it is valid:

--8<---------------cut here---------------start------------->8---
int
_hurd_raise_signal (struct hurd_sigstate *ss,
		    int signo, const struct hurd_signal_detail *detail)
{
  if (ss == NULL)
    {
      ss = _hurd_self_sigstate ();
      __spin_lock (&ss->lock);
    }

  /* Mark SIGNO as pending to be delivered.  */
  __sigaddset (&ss->pending, signo);
  ss->pending_data[signo] = *detail;
--8<---------------cut here---------------end--------------->8---

I suppose that before calling ‘sigaddset’, it should check whether SIGNO
is within bounds, along the lines of:

  if (signo < 2 || signo >= _NSIG)
    return EINVAL;

Does that make sense?

Thanks,
Ludo’.


  reply	other threads:[~2020-10-13 13:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20201005100249.19995.93553@vcs0.savannah.gnu.org>
2020-10-05 12:24 ` branch master updated: gnu: gettext-minimal: Mark "test-raise" test XFAIL on the Hurd Jan Nieuwenhuizen
2020-10-05 12:27   ` Efraim Flashner
2020-10-12 10:10   ` Ludovic Courtès
2020-10-12 11:37     ` Jan Nieuwenhuizen
2020-10-13 13:41       ` Ludovic Courtès [this message]
2020-10-13 13:57         ` raise(-1) succeeds for programs linked against libpthread Samuel Thibault
2020-10-13 20:41           ` Ludovic Courtès

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://guix.gnu.org/

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

  git send-email \
    --in-reply-to=87h7qyjl9q.fsf_-_@gnu.org \
    --to=ludo@gnu.org \
    --cc=bug-hurd@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=janneke@gnu.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.savannah.gnu.org/cgit/guix.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).