none/tests/fdleak_cmsg_supp.supp: Add suppressions for older glibc
[valgrind.git] / none / tests / pselect_alarm.c
blob7a68ec00d2d002d3b2f6ef3b2a425eb68b82d509
1 /* Tries to exploit bug in pselect mask handling:
2 https://bugs.kde.org/show_bug.cgi?id=359871
3 where client program was able to successfully block VG_SIGVGKILL. */
5 #include <sys/select.h>
6 #include <assert.h>
7 #include <errno.h>
8 #include <pthread.h>
9 #include <signal.h>
10 #include <stdio.h>
11 #include <unistd.h>
13 static int ready = 0;
14 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
15 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
17 static void *
18 mythr(void *ignore)
20 pthread_mutex_lock(&mutex);
21 ready = 1;
22 pthread_cond_signal(&cond);
23 pthread_mutex_unlock(&mutex);
25 sigset_t ss;
26 sigfillset(&ss);
27 while (1) {
28 struct timespec ts = {10000, 0};
29 pselect(0, NULL, NULL, NULL, &ts, &ss);
32 return NULL;
35 int
36 main()
38 pthread_t thr;
39 int ret = pthread_create(&thr, NULL, mythr, NULL);
40 if (ret != 0) {
41 fprintf(stderr, "pthread_create failed\n");
42 return 1;
45 pthread_mutex_lock(&mutex);
46 while (ready == 0) {
47 pthread_cond_wait(&cond, &mutex);
49 pthread_mutex_unlock(&mutex);
51 #if defined(VGO_linux)
52 assert(pselect(0, NULL, NULL, NULL, NULL, (sigset_t *)12) == -1);
53 assert(errno == EFAULT);
54 #endif
56 alarm(1); /* Unhandled SIGALRM should cause exit. */
57 while (1)
58 sleep(1);
60 return 0;