buglwIP - A Lightweight TCP/IP stack - Bugs: bug #46887, The issue about gethostbyname()...

 
 

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

bug #46887: The issue about gethostbyname() function

Submitter:  kaiqin lin <lin704932121>
Submitted:  Wed 13 Jan 2016 03:51:32 AM UTC
   
 
Category:  DNS Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Mon 07 Mar 2016 06:48:19 PM UTC, comment #5: 

Now it should be pushed :-)

Simon Goldschmidt <goldsimon>
Group administrator
Mon 07 Mar 2016 05:04:52 PM UTC, comment #4: 

Hmm, seems like I forgot to push?

Simon Goldschmidt <goldsimon>
Group administrator
Mon 07 Mar 2016 04:51:18 PM UTC, comment #3: 

Which commit fixes this bug?  I didn't see any corresponding commits in DNS code recently

Joel Cunningham <jcunningham>
Group Member
Sun 06 Mar 2016 08:30:25 PM UTC, comment #2: 

What are the attached .rar files for? I was really too lazy to hceck them.

Anyway, the problem comes from checking for valid servers only in the asynchronous path (where it is OK to call the found callback if no server is left). In the synchronous path, I have changed the code to return an error if no server is set, which should eliminate the only possibility to call the 'found' callback in direct call stack of 'dns_gethostbyname', so thi should be fixed.

Thank for reporting, and thanks for the detailed report, which made it really easy to reproduce the bug!

Simon Goldschmidt <goldsimon>
Group administrator
Wed 13 Jan 2016 02:52:45 PM UTC, comment #1: 

If DNS server ip address is not set, calling gethostbyname() may occur this issue.

kaiqin lin <lin704932121>
Wed 13 Jan 2016 03:51:32 AM UTC, original submission:  

I have a project using lwip stack with uCOS-III RTOS. lwip version is lwip-37bb0b89f062ed4fc47f0e42146dfdb065e1d6c4 that is from git.

My application thread priority is higher than lwip tcpip_thread priority.

When application  call gethostbyname(),  My RTOS detect the parameter *sem of sys_sem_signal() is uncorrect object type. After debug,  I find the problem.

The gethostbyname() calling procedure is that:


    lwip_gethostbyname()
         netconn_gethostbyname_addrtype()

              tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg));

              sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));

              sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem));


When application thread execute to sys_sem_wait() above, it will block.

Then lwip tcpip_thread will call lwip_netconn_do_gethostbyname(msg)  function whose calling procedure is that:

  

    lwip_netconn_do_gethostbyname()

         dns_gethostbyname_addrtype()

               dns_enqueue()

                     dns_check_entry()               dns.c:1379

                           dns_send()                     dns.c:985

                                 dns_call_found()      dns.c:735

lwip_netconn_do_dns_found(arg)   dns.c:899

       msg->err = ERR_VAL

                                                 sys_sem_signal(msg->sem)

After calling sys_sem_signal(msg->sem) function,   application  thread will run again immediately since its priority is higher than lwip tcpip_thread.  Then application  thread will free msg->sem by calling sys_sem_free().

Once lwip tcpip_thread continue to run,  lwip_netconn_do_gethostbyname() will check msg->err if unequal to ERR_INPROGRESS. Because msg->err is set to ERR_VAL above, so sys_sem_signal(msg->sem) will be called.However,  msg->sem is freed already.

This output info by usart is that:

      dns_enqueue: "www.baidu.com": use DNS entry 0
      dns_enqueue: "www.baidu.com": use DNS pcb 0
      dns_send: dns_servers[0] "www.baidu.com": request
      lwip_gethostbyname(www.baidu.com) failed, err=-6
      Could not find host www.baidu.com
      sys_sem_signal: err:24004

kaiqin lin <lin704932121>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #36004:  lwipopts.h added by lin704932121 (6KiB - text/x-chdr)
file #36005:  port.rar added by lin704932121 (12KiB - application/x-rar-compressed)
file #36006:  app.rar added by lin704932121 (8KiB - application/x-rar-compressed)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jcunningham (Posted a comment)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by lin704932121 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-03-07 goldsimon StatusIn Progress Fixed
    2016-03-07 goldsimon StatusFixed In Progress
    2016-03-06 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2016-01-13 lin704932121 Attached File- Added lwipopts.h, #36004
        Attached File- Added port.rar, #36005
        Attached File- Added app.rar, #36006

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code