Skip to content

Commit

Permalink
lldp_dcbx_nl: free nlh before return
Browse files Browse the repository at this point in the history
The nlh variable is allocated but not freed in some error out situations,
which could cause a resource leak. Ensure nlh is properly freed to prevent
this issue.

Fixes: a37b7e0 ("lldpad: initial git commit")
Acked-by: Loren M. Lang <[email protected]>
Signed-off-by: Hangbin Liu <[email protected]>
Signed-off-by: Aaron Conole <[email protected]>
  • Loading branch information
liuhangbin authored and apconole committed Aug 16, 2024
1 parent f5029ce commit f487b89
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lldp_dcbx_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,17 @@ static int get_state(char *ifname, __u8 *state)
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GSTATE) {
return -EIO;
rval = -EIO;
goto out;
}
if (rta->rta_type != DCB_ATTR_STATE) {
rval = -EIO;
} else {
*state = *(__u8 *)NLA_DATA(rta);
}

out:
free(nlh);

return rval;
}

Expand Down Expand Up @@ -493,11 +494,15 @@ int get_dcb_capabilities(char *ifname,
rta_parent = (struct rtattr *)(((char *)d) +
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GCAP)
return -EIO;
if (d->cmd != DCB_CMD_GCAP) {
rval = -EIO;
goto out;
}

if (rta_parent->rta_type != DCB_ATTR_CAP)
return -EIO;
if (rta_parent->rta_type != DCB_ATTR_CAP) {
rval = -EIO;
goto out;
}

rta_child = NLA_DATA(rta_parent);
rta_parent = (struct rtattr *)((char *)rta_parent +
Expand Down Expand Up @@ -540,6 +545,7 @@ int get_dcb_capabilities(char *ifname,
if (rta_parent != rta_child)
LLDPAD_DBG("rta pointers are off\n");

out:
free(nlh);
return rval;
}
Expand Down Expand Up @@ -580,11 +586,15 @@ int get_dcb_numtcs(const char *ifname, u8 *pgtcs, u8 *pfctcs)
rta_parent = (struct rtattr *)(((char *)d) +
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GNUMTCS)
return -EIO;
if (d->cmd != DCB_CMD_GNUMTCS) {
rval = -EIO;
goto out;
}

if (rta_parent->rta_type != DCB_ATTR_NUMTCS)
return -EIO;
if (rta_parent->rta_type != DCB_ATTR_NUMTCS) {
rval = -EIO;
goto out;
}

rta_child = NLA_DATA(rta_parent);
rta_parent = (struct rtattr *)((char *)rta_parent +
Expand Down Expand Up @@ -618,9 +628,10 @@ int get_dcb_numtcs(const char *ifname, u8 *pgtcs, u8 *pfctcs)
if (rta_parent != rta_child)
LLDPAD_DBG("rta pointers are off\n");

free(nlh);
if (found != 3)
rval = -EIO;
out:
free(nlh);
return rval;
}

Expand Down

0 comments on commit f487b89

Please sign in to comment.