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

solving vulnerability of string last element not null neighsync.cpp #3457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions neighsyncd/neighsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,33 @@ void NeighSync::onMsg(int nlmsg_type, struct nl_object *obj)
}

if (use_zero_mac)
{
try
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix alignment

{
std::string zero_mac = "00:00:00:00:00:00";
strncpy(macStr, zero_mac.c_str(), zero_mac.length());
macStr[sizeof(macStr) - 1] = '\0';
}
catch (const std::exception &e)
{
SWSS_LOG_ERROR("Exception during zero MAC address null termination: %s", e.what());
return;
}

}
else
{
try
{
nl_addr2str(rtnl_neigh_get_lladdr(neigh), macStr, MAX_ADDR_SIZE);
macStr[MAX_ADDR_SIZE] = '\0';
}
catch (const std::exception &e)
{
SWSS_LOG_ERROR("Exception during MAC address null termination: %s", e.what());
return;
}

}

if (!delete_key && !strncmp(macStr, "none", MAX_ADDR_SIZE))
Expand Down
Loading