1 /* Bug 28213: test for NULL pointer dereference in mq_notify.
2 Copyright The GNU Toolchain Authors.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
20 #include <sys/types.h>
28 #include <support/check.h>
31 static const char msg
[] = "hello";
34 check_bz28213_cb (union sigval sv
)
36 char buf
[sizeof (msg
)];
40 TEST_VERIFY_EXIT ((size_t) mq_receive (m
, buf
, sizeof (buf
), NULL
)
42 TEST_VERIFY_EXIT (memcmp (buf
, msg
, sizeof (buf
)) == 0);
52 memset (&sev
, '\0', sizeof (sev
));
53 sev
.sigev_notify
= SIGEV_THREAD
;
54 sev
.sigev_notify_function
= check_bz28213_cb
;
56 /* Step 1: Register & unregister notifier.
57 Helper thread should receive NOTIFY_REMOVED notification.
58 In a vulnerable version of glibc, NULL pointer dereference follows. */
59 TEST_VERIFY_EXIT (mq_notify (m
, &sev
) == 0);
60 TEST_VERIFY_EXIT (mq_notify (m
, NULL
) == 0);
62 /* Step 2: Once again, register notification.
63 Try to send one message.
64 Test is considered successful, if the callback does exit (0). */
65 TEST_VERIFY_EXIT (mq_notify (m
, &sev
) == 0);
66 TEST_VERIFY_EXIT (mq_send (m
, msg
, sizeof (msg
), 1) == 0);
75 static const char m_name
[] = "/bz28213_queue";
76 struct mq_attr m_attr
;
78 memset (&m_attr
, '\0', sizeof (m_attr
));
80 m_attr
.mq_msgsize
= sizeof (msg
);
83 O_RDWR
| O_CREAT
| O_EXCL
,
90 FAIL_UNSUPPORTED ("POSIX message queues are not implemented\n");
91 FAIL_EXIT1 ("Failed to create POSIX message queue: %m\n");
94 TEST_VERIFY_EXIT (mq_unlink (m_name
) == 0);
101 #include <support/test-driver.c>