Skip to content

Commit b8af615

Browse files
MegaManSecsquid-anubis
authored andcommitted
pinger: Echo all received bytes on Windows icmp_sock (#2210)
Avoids OOB read by strlen().
1 parent cc3d750 commit b8af615

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/icmp/IcmpPinger.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ IcmpPinger::Open(void)
5151

5252
WSADATA wsaData;
5353
WSAPROTOCOL_INFO wpi;
54-
char buf[sizeof(wpi)];
54+
char buf[sizeof(wpi)+1];
5555
int x;
5656

5757
struct sockaddr_in PS;
5858
int xerrno;
5959

60+
static_assert(sizeof(WSAPROTOCOL_INFO) >= sizeof(PS), "PS must fit into wpi-sized buf");
61+
6062
WSAStartup(2, &wsaData);
6163
atexit(Win32SockCleanup);
6264

@@ -114,7 +116,7 @@ IcmpPinger::Open(void)
114116

115117
xwrite(1, "OK\n", 3);
116118
memset(buf, 0, sizeof(buf));
117-
x = xrecv(icmp_sock, buf, sizeof(buf), 0);
119+
x = xrecv(icmp_sock, buf, sizeof(buf)-1, 0);
118120

119121
if (x < 3) {
120122
xerrno = errno;

0 commit comments

Comments
 (0)