This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] ada/35953: Guard against empty buffers and end-of-connection

* Samuel Tardieu, 2008-04-17 :

> ada/35953: Guard against empty buffers and end-of-connection

Reviving this old discussion...

> It is possible that an empty Item buffer is used with
> (Item'First - Item'Last) > 1. A call to Send_Socket with such an
> empty buffer will set its Last parameter ot Item'First - 1. This
> would be mistakenly considered as a connection closed by peer.
> This patch fixes it.

This sounds like a real bug indeed.

> diff --git a/gcc/ada/g-socket.adb b/gcc/ada/g-socket.adb
> index 10ef9aa..8c96aa0 100644
> --- a/gcc/ada/g-socket.adb
> +++ b/gcc/ada/g-socket.adb
> @@ -2113,8 +2113,8 @@ package body GNAT.Sockets is
>           Last,
>           Stream.To);
> -      if Last /= Item'Last then
> -         raise Socket_Error;
> +      if Last < Item'Last then
> +         raise Socket_Error with "packet too large for datagram";
>        end if;
>     end Write;

However I don't see how this hunk relates to the above. This changes the
behaviour of Write only in the case where Last > Item'Last, in which
case do you expect this to happen?

Furthermore this patch seems to be against some version of g-socket.adb
that does not correpond to what currently is in the FSF repository.

Other note, Socket_Error should really be raised using
Raise_Socket_Error with an appropriate errno value.


Thomas Quinot, Ph.D. ** ** Senior Software Engineer
               AdaCore -- Paris, France -- New York, USA

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]