-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi!
I tried the con_cli example but it closed the connection too soon. Thus, I activate the XMPP.logger and added some Put_Line to debug the GNUTLS.Record_Recv. After that, I found something strange on the agnutls library. I change the procedure like this:
procedure Record_Recv (S : Session;
Data : GNAT.Sockets.Vector_Type;
Length : out Ada.Streams.Stream_Element_Count)
is
N_Read : Interfaces.C.size_t;
begin
Length := 0;
for I in Data'Range loop
N_Read := gnutls_record_recv (S, Data (I).Base, Data (I).Length);
if N_Read = 0 then
gnutls_perror (Interfaces.C.int (N_Read));
raise GNUTLS_Error with "Data read = 0";
end if;
Put_Line (N_Read'Image); -- <- added
Put_Line (Ada.Streams.Stream_Element_Count'Last'Image); -- <- added
Length := Length + Ada.Streams.Stream_Element_Count (N_Read);
if N_Read < Data (I).Length then
-- nothing to read
return;
end if;
end loop;
end Record_Recv;It returned this output on the terminal:
$ examples/con_cli/main
Setting session object
Opening...
Connecting
On_Connect!
Starting idle
Waiting for data in select
Start_Stream called
Stream_Features called
Sending starttls
Sending XML : <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
Waiting for data in select
GNUTLS.Anon_Allocate_Client_Credentials
Init
GNUTLS.Transport_Set_Ptr
GNUTLS.Handshake
GnuTLS error: Resource temporarily unavailable, try again.
READ
Waiting for data in select
Handshake complete
On_Connect!
Sendinging data via TLS
Waiting for data in select
18446744073709551588
9223372036854775807
raised CONSTRAINT_ERROR : gnutls.adb:407 range check failed
I took a look at the manpage of the C gnutls_record_recv function and it says that it returns the number of bytes. I suppose that that amount of information in one record is a mistake. Maybe some casting problems?
For now, I just fixed it just ignoring the sum if the number is larger. I don't think it's the proper way but it worked:
if N_Read < Interfaces.C.size_t (Ada.Streams.Stream_Element_Count'Last) then
Length := Length + Ada.Streams.Stream_Element_Count (N_Read);
end if;Here is a patch if you want to try it.
Is there a way to fix this? Is it fine to do is?
Cheers!
Metadata
Metadata
Assignees
Labels
No labels