| commit 440b6a739aa79cef76ac928fb962ca7f43a27b0a
| Author: Kim B. Heino <[email protected]>
| Date:   Wed Oct 4 16:05:25 2017 +0300
| 
|     addconn: handle EOF from netlink as error

-                       if (readlen < 0 || salen != sizeof(sa))
+                       if (readlen <= 0 || salen != sizeof(sa))

>From <linux/netlink.h>:
#define NLMSG_OK(nlh,len) ((len) >= (int)sizeof(struct nlmsghdr) && \
                           (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
                           (nlh)->nlmsg_len <= (len))

So NLMSG_OK(nlhdr, (size_t)readlen) [a few lines down] will fail, causing 
the same result.

Unless sa.nl_pid != 0.  In that case, the new code will give up and the 
old code will try again.

I think that the old code is more correct.  Or am I misunderstanding 
something?

PS: more whining about formatting:

                if (!NLMSG_OK(nlhdr, (size_t)readlen) ||
                        nlhdr->nlmsg_type == NLMSG_ERROR)
                        return -1;

is harder for me to read than

                if (!NLMSG_OK(nlhdr, (size_t)readlen) ||
                    nlhdr->nlmsg_type == NLMSG_ERROR)
                        return -1;

Both are worse than

                if (!NLMSG_OK(nlhdr, (size_t)readlen)
                || nlhdr->nlmsg_type == NLMSG_ERROR)
                        return -1;

_______________________________________________
Swan-dev mailing list
[email protected]
https://lists.libreswan.org/mailman/listinfo/swan-dev

Reply via email to