shared: don't unconditionally set SOCK_STREAM as type in socket_address_parse()

We would set .type to a fake value. All real callers (outside of tests)
immediately overwrite .type with a proper value after calling
socket_address_parse(). So let's not set it and adjust the few places
that relied on it being set to the fake value.

socket_address_parse() is modernized to only set the output argument on
success.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-09-10 00:46:44 +02:00
parent 75af1666d7
commit 44ab234734
3 changed files with 71 additions and 51 deletions
+5 -5
View File
@@ -68,7 +68,7 @@ int socket_address_verify(const SocketAddress *a, bool strict) {
if (a->sockaddr.in.sin_port == 0)
return -EINVAL;
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
if (!IN_SET(a->type, 0, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;
@@ -80,7 +80,7 @@ int socket_address_verify(const SocketAddress *a, bool strict) {
if (a->sockaddr.in6.sin6_port == 0)
return -EINVAL;
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
if (!IN_SET(a->type, 0, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;
@@ -114,7 +114,7 @@ int socket_address_verify(const SocketAddress *a, bool strict) {
}
}
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET))
if (!IN_SET(a->type, 0, SOCK_STREAM, SOCK_DGRAM, SOCK_SEQPACKET))
return -EINVAL;
return 0;
@@ -124,7 +124,7 @@ int socket_address_verify(const SocketAddress *a, bool strict) {
if (a->size != sizeof(struct sockaddr_nl))
return -EINVAL;
if (!IN_SET(a->type, SOCK_RAW, SOCK_DGRAM))
if (!IN_SET(a->type, 0, SOCK_RAW, SOCK_DGRAM))
return -EINVAL;
return 0;
@@ -133,7 +133,7 @@ int socket_address_verify(const SocketAddress *a, bool strict) {
if (a->size != sizeof(struct sockaddr_vm))
return -EINVAL;
if (!IN_SET(a->type, SOCK_STREAM, SOCK_DGRAM))
if (!IN_SET(a->type, 0, SOCK_STREAM, SOCK_DGRAM))
return -EINVAL;
return 0;