This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos 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: tftp server:re-use of loop iterator in nested loop when CYGSEM_NET_TFTPD_MULTITHREADED=1


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


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