[6283] in bugtraq

home help back first fref pref prev next nref lref last post

Re: the purpose of dynamic memory allocation

daemon@ATHENA.MIT.EDU (Alan Cox)
Wed Mar 11 13:22:04 1998

Date: 	Wed, 11 Mar 1998 10:37:32 +0000
Reply-To: Alan Cox <alan@LXORGUK.UKUU.ORG.UK>
From: Alan Cox <alan@LXORGUK.UKUU.ORG.UK>
X-To:         jhutz+@cmu.edu
To: BUGTRAQ@NETSPACE.ORG
In-Reply-To:  <ML-2.3+1.889578441.4997.jhutz@minbar.fac.cs.cmu.edu> from
              "Jeffrey Hutzelman" at Mar 10, 98 08:07:21 pm

> > while(bytes = recv(sock, buf, bufsize, 0))
> >         write(fd, buf, bytes);
> >
> > Normally, recv fails with a 0, but if things go wrong, it will fail with a
> > -1.  The third argument to write is UNSIGNED.  If that occurs, we'll start
> > at the addr of buf, and attempt to write 4GB to the fd.  This is just one
> > example of why I do not consider signed-unsigned mismatch warnings to be
> > inconsequential.
>
> recv returns the number of bytes received, or -1 if there is an error.
> The only way it can return 0 is if a 0-byte message is received
> (e.g. a 0-length UDP packet).  While I'll agree that complaints about

0 means EOF[1]. The code above is sound until it hits an error, whereopn unless
you have 64bit files on a 32bit box it will loop harmlessly erroring the attempt
to write 4Gig of data. Its wildly improbable on a 64bit fs aware box it would
doing anything more that return "bad address" errors. But not checking for
-1 is an error.

[1] Who says you cant use recv on non datagram sockets, or on datagram protocols
that support EOF

Alan

home help back first fref pref prev next nref lref last post