Commit e1d43c4f authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

lib: criu -- Test for nil on malloc/strdup calls

Otherwise nil dereference is possible.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a7fb6a1f
......@@ -115,13 +115,30 @@ void criu_set_cpu_cap(unsigned int cap)
opts->cpu_cap = cap;
}
void criu_set_exec_cmd(int argc, char *argv[])
int criu_set_exec_cmd(int argc, char *argv[])
{
int i;
opts->n_exec_cmd = argc;
opts->exec_cmd = malloc((argc) * sizeof(char *));
for (i = 0; i < argc; i++)
if (opts->exec_cmd) {
for (i = 0; i < argc; i++) {
opts->exec_cmd[i] = strdup(argv[i]);
if (!opts->exec_cmd[i]) {
while (i > 0)
free(opts->exec_cmd[i--]);
free(opts->exec_cmd);
opts->n_exec_cmd = 0;
opts->exec_cmd = NULL;
goto out;
}
}
return 0;
}
out:
return -ENOMEM;
}
static CriuResp *recv_resp(int socket_fd)
......
......@@ -41,7 +41,7 @@ void criu_set_file_locks(bool file_locks);
void criu_set_log_level(int log_level);
void criu_set_log_file(char *log_file);
void criu_set_cpu_cap(unsigned int cap);
void criu_set_exec_cmd(int argc, char *argv[]);
int criu_set_exec_cmd(int argc, char *argv[]);
/* Here is a table of return values and errno's of functions
* from the list down below.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment