On Tue, May 23, 2023 at 11:56:18AM +0200, Claudio Jeker wrote:
> There is a lot of duplication in iked's imsg_util.c
> Now here is a minimal diff removing all extra parts added that are not
> needed anymore. The removal of ibuf_zero() depends partially on my
> previous imsg diff.
>
> With my imsg diff allocation are always zeroed so no need to call
> imsg_zero(). In ibuf_release() there is no need to call ibuf_zero() since
> the imsg API is already using freezero(). Also the NULL check is not
> needed. I moved the memset() into ibuf_reserve() so that can also go away.
>
> Iked does some rather unholy things with ibufs which I want to slowly
> clean up. This is step 1.
> --
> :wq Claudio
I am looking forward this.
ok tobhe@
>
> Index: iked.h
> ===================================================================
> RCS file: /cvs/src/sbin/iked/iked.h,v
> retrieving revision 1.210
> diff -u -p -r1.210 iked.h
> --- iked.h 5 Mar 2023 22:17:22 -0000 1.210
> +++ iked.h 22 May 2023 15:29:07 -0000
> @@ -1282,7 +1282,6 @@ struct ibuf *
> ibuf_random(size_t);
> int ibuf_prepend(struct ibuf *, void *, size_t);
> void *ibuf_advance(struct ibuf *, size_t);
> -void ibuf_zero(struct ibuf *);
> int ibuf_strcat(struct ibuf **, const char *);
> int ibuf_strlen(struct ibuf *);
>
> Index: imsg_util.c
> ===================================================================
> RCS file: /cvs/src/sbin/iked/imsg_util.c,v
> retrieving revision 1.13
> diff -u -p -r1.13 imsg_util.c
> --- imsg_util.c 17 May 2021 08:14:37 -0000 1.13
> +++ imsg_util.c 22 May 2023 15:28:39 -0000
> @@ -42,12 +42,6 @@ ibuf_cat(struct ibuf *dst, struct ibuf *
> return (ibuf_add(dst, src->buf, ibuf_size(src)));
> }
>
> -void
> -ibuf_zero(struct ibuf *buf)
> -{
> - explicit_bzero(buf->buf, buf->wpos);
> -}
> -
> struct ibuf *
> ibuf_new(const void *data, size_t len)
> {
> @@ -57,8 +51,6 @@ ibuf_new(const void *data, size_t len)
> IKED_MSGBUF_MAX)) == NULL)
> return (NULL);
>
> - ibuf_zero(buf);
> -
> if (len == 0)
> return (buf);
>
> @@ -80,37 +72,19 @@ ibuf_new(const void *data, size_t len)
> struct ibuf *
> ibuf_static(void)
> {
> - struct ibuf *buf;
> -
> - if ((buf = ibuf_open(IKED_MSGBUF_MAX)) == NULL)
> - return (NULL);
> -
> - ibuf_zero(buf);
> -
> - return (buf);
> + return ibuf_open(IKED_MSGBUF_MAX);
> }
>
> void *
> ibuf_advance(struct ibuf *buf, size_t len)
> {
> - void *ptr;
> -
> - if ((ptr = ibuf_reserve(buf, len)) != NULL)
> - memset(ptr, 0, len);
> -
> - return (ptr);
> + return ibuf_reserve(buf, len);
> }
>
> void
> ibuf_release(struct ibuf *buf)
> {
> - if (buf == NULL)
> - return;
> - if (buf->buf != NULL) {
> - ibuf_zero(buf);
> - free(buf->buf);
> - }
> - free(buf);
> + ibuf_free(buf);
> }
>
> size_t
>