Skip to content

Commit

Permalink
[swss] Replace memset functions (#2423)
Browse files Browse the repository at this point in the history
Signed-off-by: maipbui maibui@microsoft.com
What I did
Replace memset() by memset_s()
Why I did it
memset() is an insecure function that can cause buffer overflow.
  • Loading branch information
maipbui authored Sep 14, 2022
1 parent 9ff993d commit 05c5c2f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 148 deletions.
6 changes: 2 additions & 4 deletions fpmsyncd/fpmlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool FpmLink::isRawProcessing(struct nlmsghdr *h)
int len;
short encap_type = 0;
struct rtmsg *rtm;
struct rtattr *tb[RTA_MAX + 1];
struct rtattr *tb[RTA_MAX + 1] = {0};

rtm = (struct rtmsg *)NLMSG_DATA(h);

Expand All @@ -54,7 +54,6 @@ bool FpmLink::isRawProcessing(struct nlmsghdr *h)
return false;
}

memset(tb, 0, sizeof(tb));
netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);

if (!tb[RTA_MULTIPATH])
Expand Down Expand Up @@ -120,7 +119,7 @@ FpmLink::FpmLink(RouteSync *rsync, unsigned short port) :
m_server_up(false),
m_routesync(rsync)
{
struct sockaddr_in addr;
struct sockaddr_in addr = {};
int true_val = 1;

m_server_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
Expand All @@ -141,7 +140,6 @@ FpmLink::FpmLink(RouteSync *rsync, unsigned short port) :
throw system_error(errno, system_category());
}

memset (&addr, 0, sizeof (addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
Expand Down
3 changes: 1 addition & 2 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ bool RouteSync::getEvpnNextHop(struct nlmsghdr *h, int received_bytes,
void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
{
struct rtmsg *rtm;
struct rtattr *tb[RTA_MAX + 1];
struct rtattr *tb[RTA_MAX + 1] = {0};
void *dest = NULL;
char anyaddr[16] = {0};
char dstaddr[16] = {0};
Expand All @@ -360,7 +360,6 @@ void RouteSync::onEvpnRouteMsg(struct nlmsghdr *h, int len)
rtm = (struct rtmsg *)NLMSG_DATA(h);

/* Parse attributes and extract fields of interest. */
memset(tb, 0, sizeof(tb));
netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);

if (tb[RTA_DST])
Expand Down
3 changes: 1 addition & 2 deletions mclagsyncd/mclaglink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ MclagLink::MclagLink(Select *select, int port) :
m_server_up(false),
m_select(select)
{
struct sockaddr_in addr;
struct sockaddr_in addr = {};
int true_val = 1;

m_server_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
Expand All @@ -1765,7 +1765,6 @@ MclagLink::MclagLink(Select *select, int port) :
throw system_error(errno, system_category());
}

memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons((unsigned short int)port);
addr.sin_addr.s_addr = htonl(MCLAG_DEFAULT_IP);
Expand Down
Loading

0 comments on commit 05c5c2f

Please sign in to comment.