mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Address review comments on port validation.
PiperOrigin-RevId: 946184592
This commit is contained in:
committed by
Copybara-Service
parent
02354e2968
commit
2aff5d38e0
@@ -37,9 +37,9 @@ void ServiceAddressToProto(
|
||||
bool ServiceAddressFromProto(
|
||||
const location::nearby::connections::ServiceAddress& proto,
|
||||
ServiceAddress& service_address) {
|
||||
// Address must be either 4 or 16 bytes and port must be set.
|
||||
// Address must be either 4 or 16 bytes and port must be valid (1 to 65535).
|
||||
if ((proto.ip_address().size() != 16 && proto.ip_address().size() != 4) ||
|
||||
proto.port() == 0) {
|
||||
proto.port() <= 0 || proto.port() > 65535) {
|
||||
return false;
|
||||
}
|
||||
service_address.address = {proto.ip_address().begin(),
|
||||
|
||||
@@ -81,8 +81,18 @@ TEST(ServiceAddressTest, ServiceAddressFromProtoInvalidAddress) {
|
||||
TEST(ServiceAddressTest, ServiceAddressFromProtoInvalidPort) {
|
||||
ProtoServiceAddress proto;
|
||||
proto.set_ip_address(std::string("\x7f\0\0\1", 4));
|
||||
proto.set_port(0);
|
||||
ServiceAddress service_address;
|
||||
|
||||
// Port 0
|
||||
proto.set_port(0);
|
||||
EXPECT_FALSE(ServiceAddressFromProto(proto, service_address));
|
||||
|
||||
// Port > 65535
|
||||
proto.set_port(65536);
|
||||
EXPECT_FALSE(ServiceAddressFromProto(proto, service_address));
|
||||
|
||||
// Port < 0
|
||||
proto.set_port(-1);
|
||||
EXPECT_FALSE(ServiceAddressFromProto(proto, service_address));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user