Like ospfd allocate the recv buffer with malloc() on first call.
authorclaudio <claudio@openbsd.org>
Tue, 19 Jan 2021 16:02:56 +0000 (16:02 +0000)
committerclaudio <claudio@openbsd.org>
Tue, 19 Jan 2021 16:02:56 +0000 (16:02 +0000)
This code assumes some alignment of the buffer which may not be
the case with bss memory.

usr.sbin/dvmrpd/packet.c

index 757598c..0a7dd6d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: packet.c,v 1.6 2021/01/19 11:46:10 claudio Exp $ */
+/*     $OpenBSD: packet.c,v 1.7 2021/01/19 16:02:56 claudio Exp $ */
 
 /*
  * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -41,7 +41,7 @@ int            dvmrp_hdr_sanity_check(const struct ip *, struct dvmrp_hdr *,
                     u_int16_t, const struct iface *);
 struct iface   *find_iface(struct dvmrpd_conf *, struct in_addr);
 
-extern struct dvmrpd_conf      *deconf;
+static u_int8_t        *recv_buf;
 
 int
 gen_dvmrp_hdr(struct ibuf *buf, struct iface *iface, u_int8_t code)
@@ -97,7 +97,6 @@ recv_packet(int fd, short event, void *bula)
        struct nbr              *nbr = NULL;
        struct in_addr           addr;
        char                    *buf;
-       char                     pkt[READ_BUF_SIZE];
        ssize_t                  r;
        u_int16_t                len;
        int                      l;
@@ -105,14 +104,18 @@ recv_packet(int fd, short event, void *bula)
        if (event != EV_READ)
                return;
 
-       if ((r = recvfrom(fd, pkt, sizeof(pkt), 0, NULL, NULL)) == -1) {
+       if (recv_buf == NULL)
+               if ((recv_buf = malloc(READ_BUF_SIZE)) == NULL)
+                       fatal(__func__);
+
+       buf = recv_buf;
+       if ((r = recvfrom(fd, buf, READ_BUF_SIZE, 0, NULL, NULL)) == -1) {
                if (errno != EAGAIN && errno != EINTR)
                        log_debug("recv_packet: error receiving packet");
                return;
        }
 
        len = (u_int16_t)r;
-       buf = pkt;
 
        /* IP header sanity checks */
        if (len < sizeof(ip_hdr)) {