buglwIP - A Lightweight TCP/IP stack - Bugs: bug #20315, Problem in the use of tcp_listen...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #20315: Problem in the use of tcp_listen in api_msg.c

Submitted by:  Frédéric Bernon <fbernon>
Submitted on:  Mon 02 Jul 2007 08:12:33 AM UTC  
 
Category: TCPSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Frédéric Bernon <fbernon>
Open/Closed: ClosedPlanned Release: None
lwIP version: None

(Jump to the original submission Jump to the original submission)

Fri 13 Jul 2007 01:59:59 PM UTC, comment #7:

Ok, since no objects, it's check in...

Frédéric Bernon <fbernon>
Project MemberIn charge of this item.
Tue 10 Jul 2007 01:32:18 PM UTC, comment #6:

I attach a patch file. In rawapi.txt, we can read :

"tcp_listen() may return NULL if no memory was available for the
listening connection. If so, the memory associated with the pcb
passed as an argument to tcp_listen() will not be deallocated."

So, the change is only in api_msg.c. Problem, it's always possible that tcp_listen return a valid pcb, but that the sys_mbox_new for acceptmbox failed: in this case the pcb can't be used, and should be closed. The sys_mbox_new success is a port problem, so, since a LWIP_ERROR is used in netconn_accept, I think the patch is enough.

Ok for you?

(file #13282)

Frédéric Bernon <fbernon>
Project MemberIn charge of this item.
Wed 04 Jul 2007 09:23:50 AM UTC, comment #5:

It should be only in one list at every time.

It should be on the bound list when calling tcp_listen, so you'd have to remove it from there, not from the active list, that's right.

Maybe we should include a check at the beginning that it isn't active yet and fail if it is. That would solve the netconn issues with converting from connection- to listen-pcb, also. Only bad thing is we don't have a return value here...

Maybe the automatic-freeing is not so good after all...

Simon Goldschmidt <goldsimon>
Project Administrator
Wed 04 Jul 2007 09:05:37 AM UTC, comment #4:

Uhmm is the pcb in both lists (active/bound) or in only one? I will study that... Hopefully, I don't have check in yet...

Frédéric Bernon <fbernon>
Project MemberIn charge of this item.
Wed 04 Jul 2007 08:29:25 AM UTC, comment #3:

Wait a minute.
Why tcp_pcb_remove(&tcp_active_pcbs, pcb); ?
May be the same as in success case

TCP_RMV(&tcp_bound_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);

Oleg Tyshev <olegreen>
Mon 02 Jul 2007 10:04:54 AM UTC, comment #2:

Agree with you. Ok, if no objects, I will add...

tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);

in tcp_listen this afternoon...

Frédéric Bernon <fbernon>
Project MemberIn charge of this item.
Mon 02 Jul 2007 09:43:32 AM UTC, comment #1:

If returning NULL we should delete the old pcb. Otherwise we could return the old pcb, but that would leave no indication whether listen succeeded or not, so I would favour deallocating the old pcb.

Simon Goldschmidt <goldsimon>
Project Administrator
Mon 02 Jul 2007 08:12:33 AM UTC, original submission:

In do_listen (in api_msg.c file), the tcp_listen call is :

msg->conn->pcb.tcp = tcp_listen(msg->conn->pcb.tcp);

The problem is that, if tcp_listen can't alloc a tcp_pcb_listen (memp_malloc(MEMP_TCP_PCB_LISTEN) return NULL), the pcb.tcp used to listen is lost (since the msg->conn->pcb.tcp is directly set, without any error checking).

I suppose that perhaps, a processing in a TCP timer will free the pcb.tcp, but I think it should be directly delete in tcp_listen, like this:

lpcb = memp_malloc(MEMP_TCP_PCB_LISTEN);
if (lpcb == NULL) {
tcp_pcb_remove(&tcp_active_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);
return NULL;
}

Can I have your comments about that?

Frédéric Bernon <fbernon>
Project MemberIn charge of this item.

 

Attached Files
file #13282:  do_listen.txt added by fbernon (736B - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by kieranm (Updated the item)
  • -unavailable- added by olegreen (Posted a comment)
  • -unavailable- added by goldsimon (Posted a comment)
  • -unavailable- added by fbernon (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Fri 13 Jul 2007 02:00:10 PM UTCfbernonStatusNone=>Fixed
      Open/ClosedOpen=>Closed
    Fri 13 Jul 2007 11:51:13 AM UTCkieranmPlanned Release=>1.3.0
    Tue 10 Jul 2007 01:32:18 PM UTCfbernonAttached File-=>Added do_listen.txt, #13282

    Back to the top


    Powered by Savane 3.1-cleanup1