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

Submitted by:  kaiqin lin <lin704932121>
Submitted on:  Wed 13 Jan 2016 03:51:32 AM UTC  
 
Category: DNSSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned 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>
Project AdministratorIn charge of this item.
Mon 07 Mar 2016 05:04:52 PM UTC, comment #4:

Hmm, seems like I forgot to push?

Simon Goldschmidt <goldsimon>
Project AdministratorIn charge of this item.
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>
Project 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>
Project AdministratorIn charge of this item.
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 http://www.baidu.com
sys_sem_signal: err:24004

kaiqin lin <lin704932121>

 

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
  • -unavailable- added by jcunningham (Posted a comment)
  • -unavailable- added by goldsimon (Posted a comment)
  • -unavailable- added by lin704932121 (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 8 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 07 Mar 2016 06:48:19 PM UTCgoldsimonStatusIn Progress=>Fixed
    Mon 07 Mar 2016 05:04:52 PM UTCgoldsimonStatusFixed=>In Progress
    Sun 06 Mar 2016 08:30:25 PM UTCgoldsimonStatusNone=>Fixed
      Assigned toNone=>goldsimon
      Open/ClosedOpen=>Closed
    Wed 13 Jan 2016 03:51:33 AM UTClin704932121Attached 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.1-cleanup1