Skip to content

Commit

Permalink
fix searchnet segfault and racecondition
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbesen committed Feb 23, 2024
1 parent f13f0f5 commit 3621014
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ int bindDevice( int sock, const char* device )
// 0 = failed, 1 = this is a ICMP Response
int isICMPResponse( int family, unsigned char* buf, int bytes )
{
assert( family == AF_INET || family == AF_INET6);
if( family != AF_INET && family != AF_INET6 ) return 0;

if( bytes < 1 ) return 0;

Expand Down Expand Up @@ -430,7 +430,7 @@ void listener( struct PreparedPing* pp )

keep_retry_quick:
bytes = recvfrom( listenSock, (void*) buf, sizeof(buf), 0, (struct sockaddr*)&recvFromAddr, &recvFromAddrLen );
if( !isICMPResponse( pp->psaddr.sin6_family, buf, bytes) ) continue;
if( !isICMPResponse( recvFromAddr.sin6_family, buf, bytes) ) continue;

// compare the sender
if( using_regular_ping && memcmp(&recvFromAddr, &pp->psaddr, min(recvFromAddrLen, pp->psaddr_len) ) != 0 ) continue;
Expand Down
3 changes: 3 additions & 0 deletions searchnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ int main( int argc, char ** argv )
mask = 1<<(32-atoi(argv[2]));
speed = atof(argv[3]);

struct PingData localPingData;
PingData = &localPingData;

base &= ~(mask-1);
printf( "Base: %08x / Mask: %08x\n", base, mask );
for( offset = 0; offset < mask; offset++ )
Expand Down

0 comments on commit 3621014

Please sign in to comment.