On 11/08/2017 10:57 AM, Zefir Kurtisi wrote:
> On 11/07/2017 09:24 PM, Rosen Penev wrote:
>> Less verbose
>>
>> Signed-off-by: Rosen Penev <ros...@gmail.com>
>> ---
>>  interface.c | 22 ++++++++--------------
>>  1 file changed, 8 insertions(+), 14 deletions(-)
>>
>> diff --git a/interface.c b/interface.c
>> index 7f814d2..18dee52 100644
>> --- a/interface.c
>> +++ b/interface.c
>> @@ -44,7 +44,7 @@
>>  static int
>>  interface_send_packet4(struct interface *iface, struct sockaddr_in *to, 
>> struct iovec *iov, int iov_len)
>>  {
>> -    static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / 
>> sizeof(size_t)) + 1];
>> +    static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / 
>> sizeof(size_t)) + 1] = {};
>>      static struct sockaddr_in a;
>>      static struct msghdr m = {
>>              .msg_name = (struct sockaddr *) &a,
>> @@ -61,7 +61,6 @@ interface_send_packet4(struct interface *iface, struct 
>> sockaddr_in *to, struct i
>>      m.msg_iov = iov;
>>      m.msg_iovlen = iov_len;
>>  
>> -    memset(cmsg_data, 0, sizeof(cmsg_data));
>>      cmsg = CMSG_FIRSTHDR(&m);
>>      cmsg->cmsg_len = m.msg_controllen;
>>      cmsg->cmsg_level = IPPROTO_IP;
> 
> This one looks like a pitfall to me, since without the memset cmsg_data being
> static is never zeroed again at runtime. Not sure if all cmsg members are
> initialized after the removed memset, otherwise the change is wrong.
> 
> 
> Cheers,
> Zefir

Huh, good catch. But I wonder if there is any reason to make these
variables static at all - stack-allocated should be fine? I see that
re-initialization of the msghdr is avoided, but I don't consider that a
good enough reason, as it makes the code less intuitive. (And if kept
static, it should at least get a comment explaining it.)

Matthias

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to