Use ibuf_data() instead of direct access to ibuf->buf,
authorclaudio <claudio@openbsd.org>
Mon, 3 Jul 2023 09:51:38 +0000 (09:51 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 3 Jul 2023 09:51:38 +0000 (09:51 +0000)
use ibuf_size() instead of direct access to ibuf->wpos,
use ibuf_left() in places where the code checks if there is enough
space left in the ibuf.
OK tb@

usr.sbin/ospf6d/lsreq.c
usr.sbin/ospf6d/lsupdate.c
usr.sbin/ospf6d/ospfe.c
usr.sbin/ospf6d/packet.c

index 29d4133..fff9ac6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lsreq.c,v 1.14 2023/03/08 04:43:14 guenther Exp $ */
+/*     $OpenBSD: lsreq.c,v 1.15 2023/07/03 09:51:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org>
@@ -59,8 +59,9 @@ send_ls_req(struct nbr *nbr)
                goto fail;
 
        /* LSA header(s) */
-       for (le = TAILQ_FIRST(&nbr->ls_req_list); le != NULL &&
-           buf->wpos + sizeof(struct ls_req_hdr) < buf->max; le = nle) {
+       for (le = TAILQ_FIRST(&nbr->ls_req_list);
+           le != NULL && sizeof(ls_req_hdr) < ibuf_left(buf);
+           le = nle) {
                nbr->ls_req = nle = TAILQ_NEXT(le, entry);
                ls_req_hdr.zero = 0;
                ls_req_hdr.type = le->le_lsa->type;
index 3873771..935b3de 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lsupdate.c,v 1.23 2023/06/21 07:45:47 claudio Exp $ */
+/*     $OpenBSD: lsupdate.c,v 1.24 2023/07/03 09:51:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -194,7 +194,7 @@ add_ls_update(struct ibuf *buf, struct iface *iface, void *data, u_int16_t len,
        size_t          ageoff;
        u_int16_t       age;
 
-       if (buf->wpos + len >= buf->max)
+       if (len >= ibuf_left(buf))
                return (0);
 
        ageoff = ibuf_size(buf);
index bb8eb97..e10926d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ospfe.c,v 1.69 2023/06/21 07:45:47 claudio Exp $ */
+/*     $OpenBSD: ospfe.c,v 1.70 2023/07/03 09:51:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -954,18 +954,18 @@ orig_rtr_lsa(struct area *area)
        lsa_hdr.ls_id = 0;
        lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr;
        lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
-       lsa_hdr.len = htons(buf->wpos);
+       lsa_hdr.len = htons(ibuf_size(buf));
        lsa_hdr.ls_chksum = 0;          /* updated later */
        if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
                fatal("orig_rtr_lsa: ibuf_set failed");
 
-       chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+       chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET);
        if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
                fatal("orig_rtr_lsa: ibuf_set_n16 failed");
 
        if (self)
                imsg_compose_event(iev_rde, IMSG_LS_UPD, self->peerid, 0,
-                   -1, buf->buf, buf->wpos);
+                   -1, ibuf_data(buf), ibuf_size(buf));
        else
                log_warnx("orig_rtr_lsa: empty area %s",
                    inet_ntoa(area->id));
@@ -1018,7 +1018,7 @@ orig_net_lsa(struct iface *iface)
        lsa_hdr.ls_id = htonl(iface->ifindex);
        lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr;
        lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
-       lsa_hdr.len = htons(buf->wpos);
+       lsa_hdr.len = htons(ibuf_size(buf));
        lsa_hdr.ls_chksum = 0;          /* updated later */
        if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
                fatal("orig_net_lsa: ibuf_set failed");
@@ -1027,12 +1027,12 @@ orig_net_lsa(struct iface *iface)
        if (ibuf_set(buf, sizeof(lsa_hdr), &lsa_net, sizeof(lsa_net)) == -1)
                fatal("orig_net_lsa: ibuf_set failed");
 
-       chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+       chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET);
        if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
                fatal("orig_net_lsa: ibuf_set_n16 failed");
 
        imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0,
-           -1, buf->buf, buf->wpos);
+           -1, ibuf_data(buf), ibuf_size(buf));
 
        ibuf_free(buf);
 }
@@ -1116,17 +1116,17 @@ orig_link_lsa(struct iface *iface)
        lsa_hdr.ls_id = htonl(iface->ifindex);
        lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr;
        lsa_hdr.seq_num = htonl(INIT_SEQ_NUM);
-       lsa_hdr.len = htons(buf->wpos);
+       lsa_hdr.len = htons(ibuf_size(buf));
        lsa_hdr.ls_chksum = 0;          /* updated later */
        if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1)
                fatal("orig_link_lsa: ibuf_set failed");
 
-       chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET);
+       chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET);
        if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1)
                fatal("orig_link_lsa: ibuf_set_n16 failed");
 
        imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0,
-           -1, buf->buf, buf->wpos);
+           -1, ibuf_data(buf), ibuf_size(buf));
 
        ibuf_free(buf);
 }
index 26a54ad..2ed0e43 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: packet.c,v 1.21 2023/06/21 07:45:47 claudio Exp $ */
+/*     $OpenBSD: packet.c,v 1.22 2023/07/03 09:51:38 claudio Exp $ */
 
 /*
  * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -103,7 +103,7 @@ send_packet(struct iface *iface, struct ibuf *buf,
                        return (-1);
                }
 
-       if (sendto(iface->fd, buf->buf, ibuf_size(buf), 0,
+       if (sendto(iface->fd, ibuf_data(buf), ibuf_size(buf), 0,
            (struct sockaddr *)&sa6, sizeof(sa6)) == -1) {
                log_warn("send_packet: error sending packet on interface %s",
                    iface->name);