linux: Fix UB on tst-sched-setattr.c

UBSAN: Undefined behaviour in ../sysdeps/unix/sysv/linux/tst-sched_setattr.c:86:5 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0
This commit is contained in:
Adhemerval Zanella 2025-04-23 16:23:36 -03:00
parent e4b9aa70a7
commit 4b23aedb1b
1 changed files with 15 additions and 10 deletions

View File

@ -33,6 +33,20 @@ union
unsigned char padding[4096];
} u;
static void
__attribute_disable_ubsan__
check_null_argument (volatile unsigned int size)
{
/* Invalid buffer arguments result in EINVAL (not EFAULT). */
errno = 0;
void *volatile null_pointer = NULL; /* compiler barrier. */
TEST_COMPARE (sched_setattr (0, null_pointer, 0), -1);
TEST_COMPARE (errno, EINVAL);
errno = 0;
TEST_COMPARE (sched_getattr (0, null_pointer, size, 0), -1);
TEST_COMPARE (errno, EINVAL);
}
static int
do_test (void)
{
@ -79,16 +93,7 @@ do_test (void)
TEST_COMPARE (u.attr.sched_policy, SCHED_OTHER);
TEST_COMPARE (u.attr.sched_nice, 19);
/* Invalid buffer arguments result in EINVAL (not EFAULT). */
{
errno = 0;
void *volatile null_pointer = NULL; /* compiler barrier. */
TEST_COMPARE (sched_setattr (0, null_pointer, 0), -1);
TEST_COMPARE (errno, EINVAL);
errno = 0;
TEST_COMPARE (sched_getattr (0, null_pointer, size, 0), -1);
TEST_COMPARE (errno, EINVAL);
}
check_null_argument (size);
return 0;
}