method but instead of overwriting ibuf internals replace the buf a level up.
Users of ikev2_msg_send() are not allowed to hold and reuse a pointer to
msg_data (which is another footgun to disarm at some point).
OK tb@
-/* $OpenBSD: iked.h,v 1.213 2023/05/23 13:57:14 claudio Exp $ */
+/* $OpenBSD: iked.h,v 1.214 2023/05/30 08:41:15 claudio Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
ibuf_dup(struct ibuf *);
struct ibuf *
ibuf_random(size_t);
-int ibuf_prepend(struct ibuf *, void *, size_t);
int ibuf_strcat(struct ibuf **, const char *);
int ibuf_strlen(struct ibuf *);
-/* $OpenBSD: ikev2_msg.c,v 1.92 2023/05/23 13:57:14 claudio Exp $ */
+/* $OpenBSD: ikev2_msg.c,v 1.93 2023/05/30 08:41:15 claudio Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
ibuf_length(buf), isnatt ? ", NAT-T" : "");
if (isnatt) {
- if (ibuf_prepend(buf, &natt, sizeof(natt)) == -1) {
+ struct ibuf *new;
+ if ((new = ibuf_new(&natt, sizeof(natt))) == NULL) {
log_debug("%s: failed to set NAT-T", __func__);
return (-1);
}
+ if (ibuf_cat(new, buf) == -1) {
+ ibuf_free(new);
+ log_debug("%s: failed to set NAT-T", __func__);
+ return (-1);
+ }
+ ibuf_free(buf);
+ buf = msg->msg_data = new;
}
if (sendtofrom(msg->msg_fd, ibuf_data(buf), ibuf_size(buf), 0,
-/* $OpenBSD: imsg_util.c,v 1.16 2023/05/23 13:57:14 claudio Exp $ */
+/* $OpenBSD: imsg_util.c,v 1.17 2023/05/30 08:41:15 claudio Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
return (0);
}
-int
-ibuf_prepend(struct ibuf *buf, void *data, size_t len)
-{
- struct ibuf *new;
-
- /* Swap buffers (we could also use memmove here) */
- if ((new = ibuf_new(data, len)) == NULL)
- return (-1);
- if (ibuf_cat(new, buf) == -1) {
- ibuf_free(new);
- return (-1);
- }
- free(buf->buf);
- memcpy(buf, new, sizeof(*buf));
- free(new);
-
- return (0);
-}
-
int
ibuf_strcat(struct ibuf **buf, const char *s)
{