public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] return value of fdopen in cyg_httpd_process should be checked for validity
@ 2003-12-10 10:47 sandeep
  2003-12-10 12:57 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: sandeep @ 2003-12-10 10:47 UTC (permalink / raw)
  To: ecos-discuss

function cyg_httpd_process in httpd.c , has code like --

 FILE *client;
------- snipped -------
 client = fdopen( client_socket, "r+");

 /* We are really only interested in the first line.
  */
 fgets( request, sizeof(request), client );
...........
...........

If malloc fails (tracing fdopen internals) then client will be set to NULL and
further referencing
of client cause buggy behaviours. So it is clear that a validity check needs to
be done on return value of fdopen before going ahead with using it's return
value. But what should be the action in that failure case?

should one just return from that point? I guess, if we do that, it will make the
requesting browser to fail getting any response for it's request and retrying
will need to be done. Andrew, is that safe enough?

I can send the trivial patch for it, once above issue is settled.

peace
sandeep





-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] return value of fdopen in cyg_httpd_process should be checked for validity
  2003-12-10 10:47 [ECOS] return value of fdopen in cyg_httpd_process should be checked for validity sandeep
@ 2003-12-10 12:57 ` Andrew Lunn
  2003-12-11 11:27   ` Nick Garnett
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2003-12-10 12:57 UTC (permalink / raw)
  To: sandeep; +Cc: ecos-discuss

On Wed, Dec 10, 2003 at 04:20:41PM +0530, sandeep wrote:
> function cyg_httpd_process in httpd.c , has code like --
> 
>  FILE *client;
> ------- snipped -------
>  client = fdopen( client_socket, "r+");
> 
>  /* We are really only interested in the first line.
>   */
>  fgets( request, sizeof(request), client );
> ...........
> ...........
> 
> If malloc fails (tracing fdopen internals) then client will be set
> to NULL and further referencing of client cause buggy behaviours. So
> it is clear that a validity check needs to be done on return value
> of fdopen before going ahead with using it's return value. But what
> should be the action in that failure case?  should one just return
> from that point? I guess, if we do that, it will make the requesting
> browser to fail getting any response for it's request and retrying
> will need to be done. Andrew, is that safe enough?
 
Nick is the person to ask, not me. Nick wrote the code. I just added
IPv6 support.

Just returning is not enough. Doing that will result in the leak of a
socket.

        Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [ECOS] return value of fdopen in cyg_httpd_process should be checked for validity
  2003-12-10 12:57 ` Andrew Lunn
@ 2003-12-11 11:27   ` Nick Garnett
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Garnett @ 2003-12-11 11:27 UTC (permalink / raw)
  To: Andrew Lunn; +Cc: sandeep, ecos-discuss

Andrew Lunn <andrew@lunn.ch> writes:

> On Wed, Dec 10, 2003 at 04:20:41PM +0530, sandeep wrote:
> > function cyg_httpd_process in httpd.c , has code like --
> > 
> >  FILE *client;
> > ------- snipped -------
> >  client = fdopen( client_socket, "r+");
> > 
> >  /* We are really only interested in the first line.
> >   */
> >  fgets( request, sizeof(request), client );
> > ...........
> > ...........
> > 
> > If malloc fails (tracing fdopen internals) then client will be set
> > to NULL and further referencing of client cause buggy behaviours. So
> > it is clear that a validity check needs to be done on return value
> > of fdopen before going ahead with using it's return value. But what
> > should be the action in that failure case?  should one just return
> > from that point? I guess, if we do that, it will make the requesting
> > browser to fail getting any response for it's request and retrying
> > will need to be done. Andrew, is that safe enough?
>  
> Nick is the person to ask, not me. Nick wrote the code. I just added
> IPv6 support.
> 
> Just returning is not enough. Doing that will result in the leak of a
> socket.

I suspect that the correct thing to do is to send a pre-packaged
response back to the browser saying something like "Server out of
resources". This would have to be done using a plain write() followed
by a close(). It will probably also need to read() the rest of the
request header. All a bit yukky unfortunately.

-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com      The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-11 11:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-10 10:47 [ECOS] return value of fdopen in cyg_httpd_process should be checked for validity sandeep
2003-12-10 12:57 ` Andrew Lunn
2003-12-11 11:27   ` Nick Garnett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).