Skip to content

Commit 85b37e0

Browse files
remove "safe" versions of FD_SET/FD_ISSET (#6918)
The socket is a value to be assigned, not an index to be used. As such there is no safety check to be done here and doing so just breaks things. Fixes networking on Windows.
1 parent 515beef commit 85b37e0

5 files changed

Lines changed: 16 additions & 19 deletions

File tree

code/network/gtrack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void IdleGameTracker()
382382

383383
//Check for incoming
384384
FD_ZERO(&read_fds); // NOLINT
385-
FD_SET_SAFE(Psnet_socket, &read_fds);
385+
FD_SET(Psnet_socket, &read_fds);
386386

387387
if(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_GAME_TRACKER))
388388
{
@@ -689,4 +689,4 @@ static void SendClientHolePunch(sockaddr_in6 *addr)
689689
packet_length = SerializeGamePacket(&HolePunchAck, packet_data);
690690
SENDTO(Psnet_socket, reinterpret_cast<char *>(&packet_data), packet_length, 0,
691691
reinterpret_cast<LPSOCKADDR>(addr), sizeof(sockaddr_in6), PSNET_TYPE_GAME_TRACKER);
692-
}
692+
}

code/network/psnet2.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ int psnet_send(net_addr *who_to_addr, void *data, int len, int np_index) // NOLI
810810
}
811811

812812
FD_ZERO(&wfds);
813-
FD_SET_SAFE(Psnet_socket, &wfds);
813+
FD_SET(Psnet_socket, &wfds);
814814

815815
timeout.tv_sec = 0;
816816
timeout.tv_usec = 0;
@@ -821,7 +821,7 @@ int psnet_send(net_addr *who_to_addr, void *data, int len, int np_index) // NOLI
821821
}
822822

823823
// if the write file descriptor is not set, then bail!
824-
if ( !FD_ISSET_SAFE(Psnet_socket, &wfds) ) {
824+
if ( !FD_ISSET(Psnet_socket, &wfds) ) {
825825
return 0;
826826
}
827827

@@ -1997,14 +1997,14 @@ void psnet_rel_connect_to_server(PSNET_SOCKET *socket, net_addr *server_addr)
19971997
timeout.tv_usec = 0;
19981998

19991999
FD_ZERO(&read_fds);
2000-
FD_SET_SAFE(Psnet_socket, &read_fds);
2000+
FD_SET(Psnet_socket, &read_fds);
20012001

20022002
if ( SELECT(static_cast<int>(Psnet_socket+1), &read_fds, nullptr, nullptr, &timeout, PSNET_TYPE_RELIABLE) == SOCKET_ERROR ) {
20032003
break;
20042004
}
20052005

20062006
// if the file descriptor is not set, then bail!
2007-
if ( !FD_ISSET_SAFE(Psnet_socket, &read_fds) ) {
2007+
if ( !FD_ISSET(Psnet_socket, &read_fds) ) {
20082008
break;
20092009
}
20102010

@@ -2042,14 +2042,14 @@ void psnet_rel_connect_to_server(PSNET_SOCKET *socket, net_addr *server_addr)
20422042
timeout.tv_usec = 0;
20432043

20442044
FD_ZERO(&read_fds);
2045-
FD_SET_SAFE(Psnet_socket, &read_fds);
2045+
FD_SET(Psnet_socket, &read_fds);
20462046

20472047
if ( SELECT(static_cast<int>(Psnet_socket+1), &read_fds, nullptr, nullptr, &timeout, PSNET_TYPE_RELIABLE) == SOCKET_ERROR ) {
20482048
break;
20492049
}
20502050

20512051
// if the file descriptor is not set, then bail!
2052-
if ( !FD_ISSET_SAFE(Psnet_socket, &read_fds) ) {
2052+
if ( !FD_ISSET(Psnet_socket, &read_fds) ) {
20532053
continue;
20542054
}
20552055

code/network/psnet2.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ extern unsigned int Serverconn;
107107
#define PSNET_IP_MODE_V6 (1<<1)
108108
#define PSNET_IP_MODE_DUAL (PSNET_IP_MODE_V4|PSNET_IP_MODE_V6)
109109

110-
#define FD_SET_SAFE(bit, set) FD_SET((bit < 0 || bit >= FD_SETSIZE ? 0 : bit), set)
111-
#define FD_ISSET_SAFE(bit, set) FD_ISSET((bit < 0 || bit >= FD_SETSIZE ? 0 : bit), set)
112-
113110
// -------------------------------------------------------------------------------------------------------
114111
// PSNET 2 TOP LAYER FUNCTIONS - these functions simply buffer and store packets based upon type (see PSNET_TYPE_* defines)
115112
//

code/network/ptrack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ void PollPTrackNet()
623623
timeout.tv_usec=0;
624624

625625
FD_ZERO(&read_fds); // NOLINT
626-
FD_SET_SAFE(Psnet_socket, &read_fds);
626+
FD_SET(Psnet_socket, &read_fds);
627627

628628
if(SELECT(static_cast<int>(Psnet_socket+1), &read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_USER_TRACKER)){
629629
int bytesin;

code/network/valid.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ int ValidateUser(validate_id_request *valid_id, char *trackerid)
306306
timeout.tv_usec=0;
307307

308308
FD_ZERO(&read_fds); // NOLINT
309-
FD_SET_SAFE(Psnet_socket, &read_fds);
309+
FD_SET(Psnet_socket, &read_fds);
310310

311311
while(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_VALIDATION))
312312
{
@@ -357,7 +357,7 @@ void ValidIdle()
357357
timeout.tv_usec=0;
358358

359359
FD_ZERO(&read_fds); // NOLINT
360-
FD_SET_SAFE(Psnet_socket, &read_fds);
360+
FD_SET(Psnet_socket, &read_fds);
361361

362362
if(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_VALIDATION)){
363363
int bytesin;
@@ -385,7 +385,7 @@ void ValidIdle()
385385
}
386386

387387
FD_ZERO(&read_fds); // NOLINT
388-
FD_SET_SAFE(Psnet_socket, &read_fds);
388+
FD_SET(Psnet_socket, &read_fds);
389389

390390
//Check to make sure the packets ok
391391
if ( (bytesin > 0) && (bytesin == inpacket.len) ) {
@@ -614,7 +614,7 @@ int ValidateMission(vmt_validate_mission_req_struct *valid_msn)
614614
udp_packet_header inpacket;
615615

616616
FD_ZERO(&read_fds); // NOLINT
617-
FD_SET_SAFE(Psnet_socket, &read_fds);
617+
FD_SET(Psnet_socket, &read_fds);
618618

619619
addrsize = sizeof(fromaddr);
620620
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
@@ -700,7 +700,7 @@ int ValidateSquadWar(squad_war_request *sw_req, squad_war_response *sw_resp)
700700
udp_packet_header inpacket;
701701

702702
FD_ZERO(&read_fds); // NOLINT
703-
FD_SET_SAFE(Psnet_socket, &read_fds);
703+
FD_SET(Psnet_socket, &read_fds);
704704

705705
addrsize = sizeof(fromaddr);
706706
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
@@ -794,7 +794,7 @@ int ValidateData(const vmt_valid_data_req_struct *vreq)
794794
udp_packet_header inpacket;
795795

796796
FD_ZERO(&read_fds); // NOLINT
797-
FD_SET_SAFE(Psnet_socket, &read_fds);
797+
FD_SET(Psnet_socket, &read_fds);
798798

799799
addrsize = sizeof(fromaddr);
800800
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
@@ -831,4 +831,4 @@ bool IsDataIndexValid(const unsigned int idx)
831831
}
832832

833833
return (DataValidStatus[count] & 1<<index);
834-
}
834+
}

0 commit comments

Comments
 (0)