test: fix spawn_setgid_fails and spawn_setuid_fails
Don't try to set a bogus UID or GID and expect to get a meaningful error. The test expected EPERM but SunOS returns EINVAL because the id is outside of the range of valid user/group ids. Try to switch to UID/GID 0. Give up privileges first if we're root, else the setuid/setgid system call will succeed when it's expected to fail.
This commit is contained in:
parent
d0be852cb1
commit
5a3b8f9fce
@ -815,14 +815,14 @@ TEST_IMPL(spawn_setuid_fails) {
|
||||
struct passwd* pw;
|
||||
pw = getpwnam("nobody");
|
||||
ASSERT(pw != NULL);
|
||||
r = setuid(pw->pw_uid);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(0 == setgid(pw->pw_gid));
|
||||
ASSERT(0 == setuid(pw->pw_uid));
|
||||
}
|
||||
|
||||
init_process_options("spawn_helper1", exit_cb_failure_expected);
|
||||
|
||||
options.flags |= UV_PROCESS_SETUID;
|
||||
options.uid = (uv_uid_t) -42424242;
|
||||
options.uid = 0;
|
||||
|
||||
r = uv_spawn(uv_default_loop(), &process, options);
|
||||
ASSERT(r == 0);
|
||||
@ -847,14 +847,14 @@ TEST_IMPL(spawn_setgid_fails) {
|
||||
struct passwd* pw;
|
||||
pw = getpwnam("nobody");
|
||||
ASSERT(pw != NULL);
|
||||
r = setuid(pw->pw_uid);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(0 == setgid(pw->pw_gid));
|
||||
ASSERT(0 == setuid(pw->pw_uid));
|
||||
}
|
||||
|
||||
init_process_options("spawn_helper1", exit_cb_failure_expected);
|
||||
|
||||
options.flags |= UV_PROCESS_SETGID;
|
||||
options.gid = (uv_gid_t) -42424242;
|
||||
options.gid = 0;
|
||||
|
||||
r = uv_spawn(uv_default_loop(), &process, options);
|
||||
ASSERT(r == 0);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user