summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2024-08-26 13:57:35 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2024-08-26 13:57:35 +0000
commit37dd5891b10b29491f22220cf01622f41538ec68 (patch)
tree0b8986c3d2084889a10793aa94839835025e8371 /lib/libutil
parent838038e33231826b74e36c891b5dfa255330998b (diff)
Replace recallocarray() with a realloc() + memset() combo.
recallocarray(), with its guarantee that memory becoming unallocated is explicitly discarded, is too slow. In rpki-client forming one particular ibuf takes more then 4mins because every recallocarray() call ends up doing a fresh malloc + memcpy + freezero call. For sensitive data use ibuf_open() instead of ibuf_dynamic() to avoid any memory reallocations. OK tb@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/imsg-buffer.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libutil/imsg-buffer.c b/lib/libutil/imsg-buffer.c
index 0708f486ee1..d45802d8d04 100644
--- a/lib/libutil/imsg-buffer.c
+++ b/lib/libutil/imsg-buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg-buffer.c,v 1.18 2023/12/12 15:47:41 claudio Exp $ */
+/* $OpenBSD: imsg-buffer.c,v 1.19 2024/08/26 13:57:34 claudio Exp $ */
/*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -94,9 +94,10 @@ ibuf_realloc(struct ibuf *buf, size_t len)
return (-1);
}
- b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
+ b = realloc(buf->buf, buf->wpos + len);
if (b == NULL)
return (-1);
+ memset(b + buf->size, 0, buf->wpos + len - buf->size);
buf->buf = b;
buf->size = buf->wpos + len;