lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Uninitialized semaphore in TCP netconn_connect() when LWIP_


From: Grant Edwards
Subject: [lwip-users] Uninitialized semaphore in TCP netconn_connect() when LWIP_NETCONN_SEM_PER_THREAD
Date: Tue, 12 Apr 2022 21:02:46 -0000 (UTC)
User-agent: slrn/1.0.3 (Linux)

I've tracked my problems with TCP netconn_connect() to an
uninitialized semaphore in lwip_netconn_do_connect(). The semaphore
LWIP_API_MSG_SEM(msg) has never been initialized. I checked it at the
entry to the function at line 1357 and immediately before and after
the call to sys_arch_sem_wait() at line 1397.

I also added diagnostics to my arch semaphore code, and have verfied
that *LWIP_API_MSG_SEM(msg) does not contain a value that was ever
allocated by sys_sem_new() and that the pointer LWIP_API_MSG_SEM(msg)
has never been passed to sys_sem_new().

  1352  void
  1353  lwip_netconn_do_connect(void *m)
  1354  {
  1355    struct api_msg *msg = (struct api_msg *)m;
  1356    err_t err;
  1357
  [...]
  1374        case NETCONN_TCP:
  [...]
  1390              } else {
  1391                msg->conn->current_msg = msg;
  1392                /* sys_sem_signal() is called from 
lwip_netconn_do_connected (or err_tcp()),
  1393                   when the connection is established! */
  1394  #if LWIP_TCPIP_CORE_LOCKING
  1395                LWIP_ASSERT("state!", msg->conn->state == 
NETCONN_CONNECT);
  1396                UNLOCK_TCPIP_CORE();
  1397                sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
  1398                LOCK_TCPIP_CORE();
  1399                LWIP_ASSERT("state!", msg->conn->state != 
NETCONN_CONNECT);
  1400  #endif /* LWIP_TCPIP_CORE_LOCKING */
  1401                return;

LWIP_NETCONN_SEM_PER_THREAD is true, so LWIP_API_MSG_SEM(msg) expands
to msg->op_completed_sem. The msg is allocated and passed to the above
function by netconn_connect() as shown below.

Where does msg->op_completed_sem get initialized?

It seems to contain a pointer to valid RAM, but what it points to has
never been initialized as a semaphore.

Shouldn't it be the per-thread netconn semaphore?

   376  err_t
   377  netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port)
   378  {
   379    API_MSG_VAR_DECLARE(msg);
   380    err_t err;
   381  
   382    LWIP_ERROR("netconn_connect: invalid conn", (conn != NULL), return 
ERR_ARG;);
   383  
   384  #if LWIP_IPV4
   385    /* Don't propagate NULL pointer (IP_ADDR_ANY alias) to subsequent 
functions */
   386    if (addr == NULL) {
   387      addr = IP4_ADDR_ANY;
   388    }
   389  #endif /* LWIP_IPV4 */
   390  
   391    API_MSG_VAR_ALLOC(msg);
   392    API_MSG_VAR_REF(msg).conn = conn;
   393    API_MSG_VAR_REF(msg).msg.bc.ipaddr = API_MSG_VAR_REF(addr);
   394    API_MSG_VAR_REF(msg).msg.bc.port = port;
   395    err = netconn_apimsg(lwip_netconn_do_connect, &API_MSG_VAR_REF(msg));
   396    API_MSG_VAR_FREE(msg);
   397  
   398    return err;
   399  }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]