From: Vincent Bernat Date: Sun, 1 Jul 2012 08:06:37 +0000 (+0200) Subject: privsep: copy errno before sending it X-Git-Tag: 0.6.1~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5fb6f53b1d9cac52ee58e9dc92ea78aeb44bd24d;p=thirdparty%2Flldpd.git privsep: copy errno before sending it errno may be erased by some other value while sending it. We do a copy and send the copy instead. --- diff --git a/src/priv.c b/src/priv.c index 6466f0b6..bbd6ee00 100644 --- a/src/priv.c +++ b/src/priv.c @@ -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)); }