1 /* Test that __read_chk is a cancellation point (BZ #29274)
2 Copyright (C) 2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <stdint.h>
20 #include <support/xunistd.h>
21 #include <support/xthread.h>
22
23 static int pipe_fds[2];
24 static pthread_barrier_t barrier;
25
26 static void *
read_thread(void * n)27 read_thread (void *n)
28 {
29 xpthread_barrier_wait (&barrier);
30 char c;
31 /* This call should be forwarded to __read_chk because the buffer size
32 is known, but the read length is non-constant. */
33 if (read (pipe_fds[0], &c, (uintptr_t) n) != 1)
34 return (void *) -1L;
35 return 0;
36 }
37
38 static int
do_test(void)39 do_test (void)
40 {
41 xpthread_barrier_init (&barrier, 0, 2);
42 xpipe (pipe_fds);
43 pthread_t thr = xpthread_create (0, read_thread, (void *) 1L);
44 xpthread_barrier_wait (&barrier);
45 xpthread_cancel (thr);
46 xpthread_join (thr);
47 return 0;
48 }
49
50 #include <support/test-driver.c>
51