Skip to contentSkip to conversation

tests/sctp: initialize addrlen for accept(2) properly

PATCH Applied Ondrej Mosnacek 2 participants 3 messages Nov 12, 2019 – Nov 14, 2019 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/sctp: initialize addrlen for accept(2) properly

The 'addrlen' argument of accept(2) must point to a variable containing the size of the structure pointed to by 'addr'. In some cases it was being left unitialized. Fix this.

---
 tests/sctp/sctp_asconf_params_server.c | 1 +
 tests/sctp/sctp_set_peer_addr.c        | 1 +
 2 files changed, 2 insertions(+)
tests/sctp/sctp_asconf_params_server.c +1 -0
index 3333ba0..ff7473b 100644
@@ -112,6 +112,7 @@ int main(int argc, char **argv)
 		fclose(f);
 	}
 
+	sinlen = sizeof(sin);
 	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
 	if (new_sock < 0) {
 		perror("accept");
tests/sctp/sctp_set_peer_addr.c +1 -0
index 61a3a44..c35b518 100644
@@ -277,6 +277,7 @@ int main(int argc, char **argv)
 		printf("Client peer address count: %d\n", peer_count);
 
 	/* Client and server now set so accept new socket on server side. */
+	sinlen = sizeof(sin);
 	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
 	if (new_sock < 0) {
 		perror("accept");
Signature · 1 line
2.23.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ondrej Mosnacek

The 'addrlen' argument of accept(2) must point to a variable containing the size of the structure pointed to by 'addr'. In some cases it was being left unitialized. Fix this.

Quoted 30 lines
---
  tests/sctp/sctp_asconf_params_server.c | 1 +
  tests/sctp/sctp_set_peer_addr.c        | 1 +
  2 files changed, 2 insertions(+)
tests/sctp/sctp_asconf_params_server.c +1 -0
index 3333ba0..ff7473b 100644
@@ -112,6 +112,7 @@ int main(int argc, char **argv)
  		fclose(f);
  	}
 
+	sinlen = sizeof(sin);
  	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
  	if (new_sock < 0) {
  		perror("accept");
tests/sctp/sctp_set_peer_addr.c +1 -0
index 61a3a44..c35b518 100644
@@ -277,6 +277,7 @@ int main(int argc, char **argv)
  		printf("Client peer address count: %d\n", peer_count);
 
  	/* Client and server now set so accept new socket on server side. */
+	sinlen = sizeof(sin);
  	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
  	if (new_sock < 0) {
  		perror("accept");
#2 lore raw
In reply to Ondrej Mosnacek
Quoted 5 lines · Ondrej Mosnacek

The 'addrlen' argument of accept(2) must point to a variable containing the size of the structure pointed to by 'addr'. In some cases it was being left unitialized. Fix this.

Thanks, applied.

Quoted 30 lines
---
  tests/sctp/sctp_asconf_params_server.c | 1 +
  tests/sctp/sctp_set_peer_addr.c        | 1 +
  2 files changed, 2 insertions(+)
tests/sctp/sctp_asconf_params_server.c +1 -0
index 3333ba0..ff7473b 100644
@@ -112,6 +112,7 @@ int main(int argc, char **argv)
  		fclose(f);
  	}
 
+	sinlen = sizeof(sin);
  	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
  	if (new_sock < 0) {
  		perror("accept");
tests/sctp/sctp_set_peer_addr.c +1 -0
index 61a3a44..c35b518 100644
@@ -277,6 +277,7 @@ int main(int argc, char **argv)
  		printf("Client peer address count: %d\n", peer_count);
 
  	/* Client and server now set so accept new socket on server side. */
+	sinlen = sizeof(sin);
  	new_sock = accept(srv_sock, (struct sockaddr *)&sin, &sinlen);
  	if (new_sock < 0) {
  		perror("accept");