]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon/priv-bsd: fix typos in asroot_iface_description_os
authorVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 13:00:02 +0000 (15:00 +0200)
committerVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 13:26:12 +0000 (15:26 +0200)
`socket()` returns -1 on error, not 1. The previous check treated fd 1
(stdout): as the failure case and any actual socket creation failure as
success, leading to ioctl(-1, ...) afterwards.

Also fix the FreeBSD-only line that referenced an undeclared 'ift'
instead of the local 'ifr', which would have failed to compile on
FreeBSD when IFDESCRSIZE is defined (but does it happen since we never
caught this before?).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
src/daemon/priv-bsd.c

index b687cbea16dec7fb16ff4e725aec7a0a92820c2e..fcee9250ed54fd764073b806a66645e5e9787cf3 100644 (file)
@@ -211,7 +211,7 @@ asroot_iface_description_os(const char *name, const char *description)
        struct ifreq ifr = { .ifr_data = (caddr_t)descr };
 #    endif
        strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
-       if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == 1) {
+       if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
                rc = errno;
                log_warnx("privsep", "unable to open inet socket");
                return rc;
@@ -241,7 +241,7 @@ asroot_iface_description_os(const char *name, const char *description)
        } else
                snprintf(descr, sizeof(descr), "lldpd: connected to %s", description);
 #    if defined HOST_OS_FREEBSD
-       ift.ifr_buffer.length = strlen(descr);
+       ifr.ifr_buffer.length = strlen(descr);
 #    endif
        if (ioctl(sock, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
                rc = errno;