Skip to content

Commit

Permalink
Merge pull request #1177 from tych0/zero-smaller-migrate-struct
Browse files Browse the repository at this point in the history
c/r: zero a smaller than known migrate_opts struct
  • Loading branch information
Christian Brauner committed Sep 8, 2016
2 parents d32bcb1 + 2cb8042 commit 3622fda
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/lxc/lxccontainer.c
Expand Up @@ -3960,6 +3960,7 @@ static int do_lxcapi_migrate(struct lxc_container *c, unsigned int cmd,
struct migrate_opts *opts, unsigned int size)
{
int ret;
struct migrate_opts *valid_opts = opts;

/* If the caller has a bigger (newer) struct migrate_opts, let's make
* sure that the stuff on the end is zero, i.e. that they didn't ask us
Expand All @@ -3978,15 +3979,28 @@ static int do_lxcapi_migrate(struct lxc_container *c, unsigned int cmd,
}
}

/* If the caller has a smaller struct, let's zero out the end for them
* so we don't accidentally use bits of it that they didn't know about
* to initialize.
*/
if (size < sizeof(*opts)) {
valid_opts = malloc(sizeof(*opts));
if (!valid_opts)
return -ENOMEM;

memset(valid_opts, 0, sizeof(*opts));
memcpy(valid_opts, opts, size);
}

switch (cmd) {
case MIGRATE_PRE_DUMP:
ret = !__criu_pre_dump(c, opts);
ret = !__criu_pre_dump(c, valid_opts);
break;
case MIGRATE_DUMP:
ret = !__criu_dump(c, opts);
ret = !__criu_dump(c, valid_opts);
break;
case MIGRATE_RESTORE:
ret = !__criu_restore(c, opts);
ret = !__criu_restore(c, valid_opts);
break;
default:
ERROR("invalid migrate command %u", cmd);
Expand Down

0 comments on commit 3622fda

Please sign in to comment.