My plan is to make ibuf_data() return void * not uint8_t *. Because of this you can't do pointer arithmetics with that function. The following diff just uses the same construct that many other functions in ikev2_pld.c use.
This code should be rewritten but we are not there yet. The goal is to introduce a ibuf parse API that avoids all this pointer gymnastics. -- :wq Claudio Index: ikev2_pld.c =================================================================== RCS file: /cvs/src/sbin/iked/ikev2_pld.c,v retrieving revision 1.128 diff -u -p -r1.128 ikev2_pld.c --- ikev2_pld.c 23 May 2023 13:12:19 -0000 1.128 +++ ikev2_pld.c 6 Jun 2023 10:49:50 -0000 @@ -1525,9 +1525,10 @@ ikev2_pld_ts(struct iked *env, struct ik struct sockaddr_in s4; struct sockaddr_in6 s6; uint8_t buf[2][128]; + uint8_t *msgbuf = ibuf_data(msg->msg_data); uint8_t *ptr; - ptr = ibuf_data(msg->msg_data) + offset; + ptr = msgbuf + offset; switch (type) { case IKEV2_TS_IPV4_ADDR_RANGE: @@ -1867,6 +1868,7 @@ ikev2_pld_cp(struct iked *env, struct ik struct iked_addr *addr; struct sockaddr_in *in4; struct sockaddr_in6 *in6; + uint8_t *msgbuf = ibuf_data(msg->msg_data); uint8_t *ptr; size_t len; uint8_t buf[128]; @@ -1875,7 +1877,7 @@ ikev2_pld_cp(struct iked *env, struct ik if (ikev2_validate_cp(msg, offset, left, &cp)) return (-1); - ptr = ibuf_data(msg->msg_data) + offset + sizeof(cp); + ptr = msgbuf + offset + sizeof(cp); len = left - sizeof(cp); log_debug("%s: type %s length %zu",