Commit a17fa3c0 by Niklas Eiling

fix possible buffer overflow

strncat only returns its first argument and not the end of the written string. Thus "buf-pos" is always 0 and consquently no range check is performed. Signed-off-by: 's avatarNiklas Eiling <niklas.eiling@rwth-aachen.de>
parent cb82ed39
...@@ -126,8 +126,8 @@ static void exec_criu(struct criu_opts *opts) ...@@ -126,8 +126,8 @@ static void exec_criu(struct criu_opts *opts)
int netnr = 0; int netnr = 0;
struct lxc_list *it; struct lxc_list *it;
char buf[4096], *pos, tty_info[32]; char buf[4096], tty_info[32];
size_t pos;
/* If we are currently in a cgroup /foo/bar, and the container is in a /* If we are currently in a cgroup /foo/bar, and the container is in a
* cgroup /lxc/foo, lxcfs will give us an ENOENT if some task in the * cgroup /lxc/foo, lxcfs will give us an ENOENT if some task in the
* container has an open fd that points to one of the cgroup files * container has an open fd that points to one of the cgroup files
...@@ -363,10 +363,11 @@ static void exec_criu(struct criu_opts *opts) ...@@ -363,10 +363,11 @@ static void exec_criu(struct criu_opts *opts)
argv[argc] = NULL; argv[argc] = NULL;
buf[0] = 0; buf[0] = 0;
pos = buf; pos = 0;
for (i = 0; argv[i]; i++) { for (i = 0; argv[i]; i++) {
pos = strncat(buf, argv[i], buf + sizeof(buf) - pos); strncat(buf, argv[i], sizeof(buf) - pos - 1);
pos = strncat(buf, " ", buf + sizeof(buf) - pos); strncat(buf, " ", sizeof(buf) - pos - 1);
pos += strlen(argv[i]);
} }
INFO("execing: %s", buf); INFO("execing: %s", buf);
......
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