From 55dff04cf4161ab498af25ce9759adc0ac012c03 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 25 Jan 2025 10:54:38 -0500 Subject: [PATCH] libprocstat: Use calloc for procstat_getcompartments output buffer This ensures the trailing bytes of the compartment name are always zeroed in the output buffer. --- lib/libprocstat/libprocstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index f132ea0ee766..b561beb2b52a 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -461,7 +461,7 @@ procstat_getcompartments(struct procstat *procstat, struct kinfo_proc *kp, } /* Unpack elements of the input buffer into the output buffer. */ - outbuf = malloc(n * sizeof(*outbuf)); + outbuf = calloc(n, sizeof(*outbuf)); if (outbuf == NULL) goto out_free; for (i = 0, cur = 0; i < n; ++i) {