Another ibuf_seek() -> ibuf_set_n16() conversions.
While there also switch to ibuf_data() and ibuf_size().

Anyone still uses ripd that can test this?
-- 
:wq Claudio

Index: auth.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/auth.c,v
retrieving revision 1.12
diff -u -p -r1.12 auth.c
--- auth.c      19 Dec 2019 16:47:14 -0000      1.12
+++ auth.c      16 Jun 2023 10:29:23 -0000
@@ -21,6 +21,7 @@
 #include <sys/socket.h>
 #include <limits.h>
 #include <md5.h>
+#include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -236,14 +237,14 @@ auth_add_trailer(struct ibuf *buf, struc
        MD5_CTX                  hash;
        u_int8_t                 digest[MD5_DIGEST_LENGTH];
        struct auth_md          *md;
-       struct md5_auth         *a;
-       int                      pos;
+       size_t                   pos;
 
-       pos = sizeof(struct rip_hdr) + sizeof(struct rip_auth);
+       pos = sizeof(struct rip_hdr) + sizeof(struct rip_auth) +
+           offsetof(struct md5_auth, auth_offset);
 
        /* add offset to header */
-       a = ibuf_seek(buf, pos, sizeof(*a));
-       a->auth_offset = htons(buf->wpos);
+       if (ibuf_set_n16(buf, pos, ibuf_size(buf)) == -1)
+               return (-1);
 
        /* insert plaintext key */
        if ((md = md_list_find(&iface->auth_md_list,
@@ -259,7 +260,7 @@ auth_add_trailer(struct ibuf *buf, struc
 
        /* calculate MD5 digest */
        MD5Init(&hash);
-       MD5Update(&hash, buf->buf, buf->wpos);
+       MD5Update(&hash, ibuf_data(buf), ibuf_size(buf));
        MD5Update(&hash, digest, MD5_DIGEST_LENGTH);
        MD5Final(digest, &hash);
 

Reply via email to