public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] tftp server:re-use of loop iterator in nested loop when CYGSEM_NET_TFTPD_MULTITHREADED=1
@ 2011-03-23 13:27 Jürgen Lambrecht
  2011-03-23 13:40 ` Andrew Lunn
  0 siblings, 1 reply; 2+ messages in thread
From: Jürgen Lambrecht @ 2011-03-23 13:27 UTC (permalink / raw)
  To: ecos

Hello,

We were looking at the code 
ecos/packages/net/common/current/src/tftp_server.c.
(ecos 3.x)
In the function 'tftpd_server(cyg_addrword_t p)', lines 647-668, the 
iterator 'i' is used in 2 nested for loops:

     for (i=0; i < CYGNUM_NET_MAX_INET_PROTOS; i++) {
       if (server->s[i] && FD_ISSET(server->s[i],&readfds)) {
         recv_len = sizeof(data);
         from_len = sizeof(from_addr);
         data_len = recvfrom(server->s[i], hdr, recv_len, 0,
&from_addr, &from_len);
         if ( data_len < 0) {
           diag_printf("TFTPD [%x]: can't read request\n", p);
         } else {
#ifdef CYGSEM_NET_TFTPD_MULTITHREADED
           // Close the socket and post on the semaphore some
           // another thread can start listening for requests. This
           // is not quite right. select could of returned with more than
           // one socket with data to read. Here we only deal with one 
of them
           for (i=0; i < CYGNUM_NET_MAX_INET_PROTOS; i++) {
             if (server->s[i]) {
               close (server->s[i]);
               server->s[i] = 0;
             }
           }
           sem_post(server->port);
#endif

At first sight, I would say this is a bug, or am I wrong?

Kind regards,
Jürgen

-- 
Jürgen Lambrecht
R&D Associate
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk


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

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

* Re: [ECOS] tftp server:re-use of loop iterator in nested loop when CYGSEM_NET_TFTPD_MULTITHREADED=1
  2011-03-23 13:27 [ECOS] tftp server:re-use of loop iterator in nested loop when CYGSEM_NET_TFTPD_MULTITHREADED=1 Jürgen Lambrecht
@ 2011-03-23 13:40 ` Andrew Lunn
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2011-03-23 13:40 UTC (permalink / raw)
  To: J?rgen Lambrecht; +Cc: ecos

On Tue, Mar 22, 2011 at 02:05:19PM +0100, J?rgen Lambrecht wrote:
> Hello,
> 
> We were looking at the code
> ecos/packages/net/common/current/src/tftp_server.c.
> (ecos 3.x)
> In the function 'tftpd_server(cyg_addrword_t p)', lines 647-668, the
> iterator 'i' is used in 2 nested for loops:
> 
>     for (i=0; i < CYGNUM_NET_MAX_INET_PROTOS; i++) {
>       if (server->s[i] && FD_ISSET(server->s[i],&readfds)) {
>         recv_len = sizeof(data);
>         from_len = sizeof(from_addr);
>         data_len = recvfrom(server->s[i], hdr, recv_len, 0,
> &from_addr, &from_len);
>         if ( data_len < 0) {
>           diag_printf("TFTPD [%x]: can't read request\n", p);
>         } else {
> #ifdef CYGSEM_NET_TFTPD_MULTITHREADED
>           // Close the socket and post on the semaphore some
>           // another thread can start listening for requests. This
>           // is not quite right. select could of returned with more than
>           // one socket with data to read. Here we only deal with
> one of them
>           for (i=0; i < CYGNUM_NET_MAX_INET_PROTOS; i++) {
>             if (server->s[i]) {
>               close (server->s[i]);
>               server->s[i] = 0;
>             }
>           }
>           sem_post(server->port);
> #endif
> 
> At first sight, I would say this is a bug, or am I wrong?

Hi Joergen

Yes, it looks like a bug, and it is probably i bug i introduced when i
added IPv6 support. I think just changing the inner loop to j should
fix any problems.

    Andrew

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

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

end of thread, other threads:[~2011-03-22 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-23 13:27 [ECOS] tftp server:re-use of loop iterator in nested loop when CYGSEM_NET_TFTPD_MULTITHREADED=1 Jürgen Lambrecht
2011-03-23 13:40 ` Andrew Lunn

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).