lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Bad assert in lwip_sendto


From: Jonathan Larmour
Subject: Re: [lwip-users] Bad assert in lwip_sendto
Date: Tue, 29 Apr 2008 17:49:53 +0100
User-agent: Thunderbird 1.5.0.12 (X11/20070530)

address@hidden wrote:
> I'm a bit uncertain here, so please correct me if I'm wrong. This is
> from the CVS head, in sockets.c:
> 
> LWIP_ERROR("lwip_sendto: invalid address",
>   (((to == NULL) && (tolen == 0)) ||
>   ((tolen == sizeof(struct sockaddr_in)) &&
>   ((((struct sockaddr_in *)to)->sin_family) == AF_INET))),
>   sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
> 
> The first condition, ((to == NULL) && (tolen == 0)), is as far as I
> can tell not desired, so shouldn't it be ((to != NULL) && (tolen !=
> 0)) instead?

Actually no. What the test is essentially saying is that it's ok for 'to'
be NULL as long as 'tolen' is 0. But if 'to' is set then tolen has to be
the right length and the sin_family has to be right.

Then further down in lwip_sendto you can see that the code behaves
differently depending on whether 'to' is set or NULL.

Admittedly in the case of LWIP_TCPIP_CORE_LOCKING 'to' is not tested, but
that's because that code is experimental, and it says explicitly in the
comment:
  /* Should only be consider like a sample or a simple way to experiment
this option (no check of "to" field...) */
So this restriction is known.

> The explanation for the LWIP_ERROR macro also seems to state the
> opposite of what the code does, no?
> 
> /** print "m" message only if "e" is true, and execute "h" expression */
> #ifndef LWIP_ERROR
> #define LWIP_ERROR(m,e,h) do { if (!(e)) { LWIP_PLATFORM_ASSERT(m); h;}}
> while(0)
> #endif /* LWIP_ERROR */

Oops yes. The code is right, the comment is wrong. I'll check in a fix
right away.

Jifl
-- 
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
------["Si fractum non sit, noli id reficere"]------       Opinions==mine




reply via email to

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