mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-29 00:11:41 +00:00
修复setgid之后还带有root组的问题,并增加测试18
This commit is contained in:
parent
9b9444fb20
commit
8ff369c9b1
4
runner.c
4
runner.c
@ -12,6 +12,7 @@
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
#include <grp.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/wait.h>
|
||||
@ -40,6 +41,7 @@ int child_process(void *clone_args){
|
||||
struct config *config = ((struct clone_args *)clone_args)->config;
|
||||
FILE *in_file = NULL, *out_file = NULL, *err_file = NULL;
|
||||
struct rlimit memory_limit, cpu_time_rlimit;
|
||||
gid_t group_list[] = {config->gid};
|
||||
#ifndef __APPLE__
|
||||
int i;
|
||||
int syscalls_whitelist[] = {SCMP_SYS(read), SCMP_SYS(fstat),
|
||||
@ -123,7 +125,7 @@ int child_process(void *clone_args){
|
||||
ERROR(log_fp, DUP2_FAILED);
|
||||
}
|
||||
}
|
||||
if (config->gid != -1 && setgid(config->gid) == -1) {
|
||||
if (config->gid != -1 && (setgid(config->gid) == -1 || setgroups(sizeof(group_list) / sizeof(gid_t), group_list) == -1)) {
|
||||
LOG_FATAL(log_fp, "setgid failed, errno: %d", errno);
|
||||
ERROR(log_fp, SET_GID_FAILED);
|
||||
}
|
||||
|
8
tests/18/Main.c
Normal file
8
tests/18/Main.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
system("id");
|
||||
return 0;
|
||||
}
|
1
tests/18/config
Normal file
1
tests/18/config
Normal file
@ -0,0 +1 @@
|
||||
{"language": "c", "max_cpu_time": 2000, "max_memory": 200000000, "use_sandbox": false, "use_nobody": true}
|
0
tests/18/in
Normal file
0
tests/18/in
Normal file
1
tests/18/out
Normal file
1
tests/18/out
Normal file
@ -0,0 +1 @@
|
||||
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
|
1
tests/18/result
Normal file
1
tests/18/result
Normal file
@ -0,0 +1 @@
|
||||
{"flag": 0, "signal": 0}
|
Loading…
Reference in New Issue
Block a user