Skip to content

Commit

Permalink
lxc_user_nic: fix get_mtu() error handling
Browse files Browse the repository at this point in the history
get_mtu() returns int, but "mtu" variable has unsigned int type.
It leads to logical error in error handling, which can end up
with strange -EINVAL error in lxc_veth_create(), cause (mtu > 0)
condition is met, but negative "mtu" value is too large when set
as mtu for network device.

Issue #4232

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
  • Loading branch information
mihalicyn committed Jan 6, 2023
1 parent 440727e commit 4967094
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lxc/cmd/lxc_user_nic.c
Expand Up @@ -502,7 +502,7 @@ static int get_mtu(char *name)

static int create_nic(char *nic, char *br, int pid, char **cnic)
{
unsigned int mtu = 1500;
int mtu = 1500;
int ret;
char veth1buf[IFNAMSIZ], veth2buf[IFNAMSIZ];

Expand All @@ -520,11 +520,11 @@ static int create_nic(char *nic, char *br, int pid, char **cnic)

if (strcmp(br, "none"))
mtu = get_mtu(br);
if (!mtu)
if (mtu <= 0)
mtu = 1500;

/* create the nics */
ret = instantiate_veth(veth1buf, veth2buf, pid, mtu);
ret = instantiate_veth(veth1buf, veth2buf, pid, (unsigned int)mtu);
if (ret < 0) {
usernic_error("%s", "Error creating veth tunnel\n");
return -1;
Expand Down

0 comments on commit 4967094

Please sign in to comment.