]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
privsep: copy errno before sending it
authorVincent Bernat <bernat@luffy.cx>
Sun, 1 Jul 2012 08:06:37 +0000 (10:06 +0200)
committerVincent Bernat <bernat@luffy.cx>
Sun, 1 Jul 2012 08:06:37 +0000 (10:06 +0200)
errno may be erased by some other value while sending it. We do a copy
and send the copy instead.

src/priv.c

index 6466f0b6eaff8aeb5557e212f15359540a1da42f..bbd6ee008b9ce8e70bae8e702f58d7868a21a04a 100644 (file)
@@ -307,7 +307,7 @@ static void
 asroot_iface_init()
 {
        struct sockaddr_ll sa;
-       int s;
+       int s, rc = 0;
        char ifname[IFNAMSIZ];
 
        must_read(remote, ifname, IFNAMSIZ);
@@ -316,7 +316,8 @@ asroot_iface_init()
        /* Open listening socket to receive/send frames */
        if ((s = socket(PF_PACKET, SOCK_RAW,
                    htons(ETH_P_ALL))) < 0) {
-               must_write(remote, &errno, sizeof(errno));
+               rc = errno;
+               must_write(remote, &rc, sizeof(rc));
                return;
        }
        memset(&sa, 0, sizeof(sa));
@@ -324,12 +325,12 @@ asroot_iface_init()
        sa.sll_protocol = 0;
        sa.sll_ifindex = if_nametoindex(ifname);
        if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) < 0) {
-               must_write(remote, &errno, sizeof(errno));
+               rc = errno;
+               must_write(remote, &rc, sizeof(rc));
                close(s);
                return;
        }
-       errno = 0;
-       must_write(remote, &errno, sizeof(errno));
+       must_write(remote, &rc, sizeof(rc));
        send_fd(remote, s);
        close(s);
 }
@@ -346,10 +347,8 @@ asroot_iface_multicast()
        must_read(remote, &add, sizeof(int));
 
        if (ioctl(sock, (add)?SIOCADDMULTI:SIOCDELMULTI,
-               &ifr) < 0) {
-               must_write(remote, &errno, sizeof(errno));
-               return;
-       }
+               &ifr) < 0)
+               rc = errno;
 
        must_write(remote, &rc, sizeof(rc));
 }