From 29e0246c68efd4b68f9593ff26b3c123fb05161d Mon Sep 17 00:00:00 2001 From: Pierre-Marie de Rodat Date: Fri, 22 Mar 2019 13:59:02 +0000 Subject: [PATCH] [Ada] GNAT.Sockets: fix recent regressions The support for IPv6 that was added since last release triggered regressions on various platforms. The size of structures passed to low level routines was not correct anymore: it should depend on the address family, now. 2019-03-22 Dmitriy Anisimkov gcc/ada/ PR ada/89583 * libgnat/g-socket.adb (Bind_Socket, Connect_Socket, Send_Socket): Fix the computation of structure lengths passed to low level routines. (Is_IPv6_Address): Fix the number of expected colons. 2019-03-22 Simon Wright gcc/testsuite/ PR ada/89583 * gnat.dg/socket2.adb: New. From-SVN: r269873 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/libgnat/g-socket.adb | 13 ++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/socket2.adb | 16 ++++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/socket2.adb diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 6cb538945ed..81b5db972c4 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2019-03-22 Dmitriy Anisimkov + + PR ada/89583 + * libgnat/g-socket.adb (Bind_Socket, Connect_Socket, + Send_Socket): Fix the computation of structure lengths passed to + low level routines. + (Is_IPv6_Address): Fix the number of expected colons. + 2019-03-11 Martin Liska * gcc-interface/misc.c (gnat_post_options): Wrap option name in string diff --git a/gcc/ada/libgnat/g-socket.adb b/gcc/ada/libgnat/g-socket.adb index c0b307964c5..476a213b038 100644 --- a/gcc/ada/libgnat/g-socket.adb +++ b/gcc/ada/libgnat/g-socket.adb @@ -461,12 +461,12 @@ package body GNAT.Sockets is is Res : C.int; Sin : aliased Sockaddr; - Len : constant C.int := Sin'Size / 8; begin Set_Address (Sin'Unchecked_Access, Address); - Res := C_Bind (C.int (Socket), Sin'Address, Len); + Res := C_Bind + (C.int (Socket), Sin'Address, C.int (Lengths (Address.Family))); if Res = Failure then Raise_Socket_Error (Socket_Errno); @@ -666,12 +666,11 @@ package body GNAT.Sockets is Server : Sock_Addr_Type) return C.int is Sin : aliased Sockaddr; - Len : constant C.int := Sin'Size / 8; - begin Set_Address (Sin'Unchecked_Access, Server); - return C_Connect (C.int (Socket), Sin'Address, Len); + return C_Connect + (C.int (Socket), Sin'Address, C.int (Lengths (Server.Family))); end Connect_Socket; procedure Connect_Socket @@ -1794,7 +1793,7 @@ package body GNAT.Sockets is end if; end loop; - return Colons <= 7; + return Colons <= 8; end Is_IPv6_Address; --------------------- @@ -2403,7 +2402,7 @@ package body GNAT.Sockets is if To /= null then Set_Address (Sin'Unchecked_Access, To.all); C_To := Sin'Address; - Len := Sin'Size / 8; + Len := C.int (Thin_Common.Lengths (To.Family)); else C_To := System.Null_Address; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6f17f242b4f..2fee0da5386 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-22 Simon Wright + + PR ada/89583 + * gnat.dg/socket2.adb: New. + 2019-03-22 Bill Schmidt * gcc.target/powerpc/mmx-psubd-2.c: Test _m_psubd. diff --git a/gcc/testsuite/gnat.dg/socket2.adb b/gcc/testsuite/gnat.dg/socket2.adb new file mode 100644 index 00000000000..2ca5288fb77 --- /dev/null +++ b/gcc/testsuite/gnat.dg/socket2.adb @@ -0,0 +1,16 @@ +-- { dg-do run } +with GNAT.Sockets; +procedure Socket2 is + Address : GNAT.Sockets.Sock_Addr_Type; + Server_Socket : GNAT.Sockets.Socket_Type; +begin + Address.Addr := GNAT.Sockets.Any_Inet_Addr; + Address.Port := 16#1234#; + GNAT.Sockets.Create_Socket (Server_Socket); + GNAT.Sockets.Set_Socket_Option + (Server_Socket, + GNAT.Sockets.Socket_Level, + (GNAT.Sockets.Reuse_Address, True)); + GNAT.Sockets.Bind_Socket (Server_Socket, Address); + GNAT.Sockets.Close_Socket (Server_Socket); +end Socket2; -- 2.30.2