add args and env number limit

This commit is contained in:
virusdefender 2016-11-05 09:27:51 +08:00
parent f0cda9f569
commit c015447307
3 changed files with 9 additions and 6 deletions

View File

@ -18,7 +18,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
PyObject *args_list, *env_list, *rule_name, *args_iter, *env_iter, *next;
int count = 0;
int count = 0, i = 0;
static char *kwargs_list[] = {"max_cpu_time", "max_real_time", "max_memory",
"max_process_number", "max_output_size",
@ -41,7 +41,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
}
_config.args[count++] = _config.exe_path;
args_iter = PyObject_GetIter(args_list);
while (1) {
for(i = 0;i < ARGS_MAX_NUMBER;i++) {
next = PyIter_Next(args_iter);
if (!next) {
break;
@ -65,7 +65,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
RaiseValueError("env must be a list");
}
env_iter = PyObject_GetIter(env_list);
while (1) {
for(i = 0;i < ENV_MAX_NUMBER; i++) {
next = PyIter_Next(env_iter);
if (!next) {
break;

View File

@ -81,7 +81,7 @@ void run(struct config *_config, struct result *_result) {
// wait for child process to terminate
// on success, returns the process ID of the child whose state has changed;
// On error, -1 is returned.
if (wait4(child_pid, &status, 0, &resource_usage) == -1) {
if (wait4(child_pid, &status, WSTOPPED, &resource_usage) == -1) {
kill_pid(child_pid);
ERROR_EXIT(WAIT_FAILED);
}

View File

@ -19,6 +19,9 @@
return; \
}
#define ARGS_MAX_NUMBER 256
#define ENV_MAX_NUMBER 256
enum {
SUCCESS = 0,
@ -46,8 +49,8 @@ struct config {
char *input_path;
char *output_path;
char *error_path;
char *args[256];
char *env[256];
char *args[ARGS_MAX_NUMBER];
char *env[ENV_MAX_NUMBER];
char *log_path;
char *seccomp_rule_name;
uid_t uid;