增加参数检查

- 使用nobody之前检查是否是root用户
 - 限制参数和环境变量数量
This commit is contained in:
virusdefender 2016-03-13 15:07:10 +08:00
parent 8aaf862224
commit 7f215ccb5a
2 changed files with 16 additions and 0 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ runner
CMakeLists.txt
main
demo
.DS_Store

View File

@ -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",