Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boundary check before memset, memcpy, strncpy #278

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/iccpd/src/iccp_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ int set_peer_link(int mid, const char* ifname)
csm->mlag_id, ifname);
}

if (MAX_L_PORT_NAME > strlen(csm->peer_itf_name))
{
ICCPD_LOG_ERR(__FUNCTION__, "MAX=%d is greater than peer_itf_name length=%d", MAX_L_PORT_NAME, strlen(csm->peer_itf_name));
return MCLAG_ERROR;
}
memset(csm->peer_itf_name, 0, MAX_L_PORT_NAME);
if (len > strlen(csm->peer_itf_name))
{
ICCPD_LOG_ERR(__FUNCTION__, "len=%d is greater than peer_itf_name length=%d", len, strlen(csm->peer_itf_name));
return MCLAG_ERROR;
}
memcpy(csm->peer_itf_name, ifname, len);

/* update peer-link link handler*/
Expand Down Expand Up @@ -208,8 +218,18 @@ int set_local_address(int mid, const char* addr)

len = strlen(addr);
memset(csm->sender_ip, 0, INET_ADDRSTRLEN);
if (len > strlen(csm->sender_ip))
{
ICCPD_LOG_ERR(__FUNCTION__, "len=%d is greater than sender_ip length=%d", len, strlen(csm->sender_ip));
return MCLAG_ERROR;
}
memcpy(csm->sender_ip, addr, len);
memset(csm->iccp_info.sender_name, 0, INET_ADDRSTRLEN);
if (len > strlen(csm->iccp_info.sender_name))
{
ICCPD_LOG_ERR(__FUNCTION__, "len=%d is greater than sender_name length=%d", len, strlen(csm->iccp_info.sender_name));
return MCLAG_ERROR;
}
memcpy(csm->iccp_info.sender_name, addr, len);

return 0;
Expand Down Expand Up @@ -268,6 +288,11 @@ int set_peer_address(int mid, const char* addr)
}

memset(csm->peer_ip, 0, INET_ADDRSTRLEN);
if (len > strlen(csm->peer_ip))
{
ICCPD_LOG_ERR(__FUNCTION__, "len=%d is greater than peer_ip length=%d", len, strlen(csm->peer_ip));
return MCLAG_ERROR;
}
memcpy(csm->peer_ip, addr, len);

return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/iccpd/src/iccp_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ int iccp_config_from_command(char * line)
cp++;

slen = cp - start;
if (slen > strlen(token))
{
return MCLAG_ERROR;
}
strncpy(token, start, slen);
*(token + slen) = '\0';
iccp_cli_attach_mclag_domain_to_port_channel(mid, token);
Expand Down