Skip to content

Commit

Permalink
lxc-user-nic: validate request
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
  • Loading branch information
Christian Brauner committed May 18, 2019
1 parent 45bfff5 commit 7c03125
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lxc/cmd/lxc_user_nic.c
Expand Up @@ -1090,6 +1090,18 @@ static bool is_privileged_over_netns(int netns_fd)
return bret;
}

static inline int validate_args(const struct user_nic_args *args, int argc)
{
int request = -EINVAL;

if (!strcmp(args->cmd, "create"))
request = LXC_USERNIC_CREATE;
else if (!strcmp(args->cmd, "delete"))
request = LXC_USERNIC_DELETE;

return request;
}

int main(int argc, char *argv[])
{
__do_free char *me = NULL, *newname = NULL, *nicname = NULL;
Expand All @@ -1113,11 +1125,8 @@ int main(int argc, char *argv[])
if (argc == 8)
args.veth_name = argv[7];

if (!strcmp(args.cmd, "create"))
request = LXC_USERNIC_CREATE;
else if (!strcmp(args.cmd, "delete"))
request = LXC_USERNIC_DELETE;
else
request = validate_args(&args, argc);
if (request < 0)
usage(true);

/* Set a sane env, because we are setuid-root. */
Expand Down

0 comments on commit 7c03125

Please sign in to comment.