mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-29 16:31:42 +00:00
增加参数检查
- 使用nobody之前检查是否是root用户 - 限制参数和环境变量数量
This commit is contained in:
parent
8aaf862224
commit
7f215ccb5a
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ runner
|
||||
CMakeLists.txt
|
||||
main
|
||||
demo
|
||||
.DS_Store
|
||||
|
15
judger.c
15
judger.c
@ -1,3 +1,5 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <python2.7/Python.h>
|
||||
#include "runner.h"
|
||||
|
||||
@ -53,6 +55,10 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
}
|
||||
config.args[count] = PyString_AsString(next);
|
||||
count++;
|
||||
if(count > 95) {
|
||||
PyErr_SetString(PyExc_ValueError, "max number of args is 95");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
config.args[count] = NULL;
|
||||
@ -75,6 +81,10 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
}
|
||||
config.env[count] = PyString_AsString(next);
|
||||
count++;
|
||||
if(count > 95) {
|
||||
PyErr_SetString(PyExc_ValueError, "max number of env is 95");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
config.env[count] = NULL;
|
||||
@ -101,6 +111,11 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
config.use_nobody = 1;
|
||||
}
|
||||
|
||||
if(config.use_nobody && getuid() != 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "root use is required when using nobody");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
run(&config, &result);
|
||||
return Py_BuildValue("{s:i, s:l, s:i, s:i, s:i, s:i}",
|
||||
"cpu_time", result.cpu_time, "memory", result.memory, "real_time", result.real_time, "signal",
|
||||
|
Loading…
Reference in New Issue
Block a user