Fix undefined behavior in unit test

Fixes #1194
This commit is contained in:
Justine Tunney 2024-05-29 20:31:46 -07:00
parent e4d25d68e4
commit 500a47bc2f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328

View file

@ -356,18 +356,18 @@ TEST(open, readOnlyCreatMode) {
ASSERT_EQ(0100500, st.st_mode);
if (getuid()) {
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT));
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT, 0666));
} else {
// root is invulnerable to eacces
ASSERT_SYS(0, 3, open("x", O_RDWR));
ASSERT_SYS(0, 0, close(3));
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT));
ASSERT_SYS(0, 3, open("x", O_RDWR | O_CREAT, 0666));
ASSERT_SYS(0, 0, close(3));
SPAWN(fork);
setuid(1000);
setgid(1000);
ASSERT_SYS(EACCES, -1, open("x", O_RDWR));
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT));
ASSERT_SYS(EACCES, -1, open("x", O_RDWR | O_CREAT, 0666));
EXITS(0);
}
}