From 9272c79b768240ff4e11f6b6dc9fa42cb6dd9177 Mon Sep 17 00:00:00 2001 From: mlelstv Date: Sat, 4 May 2024 13:33:18 +0000 Subject: [PATCH] Account for trailing NUL bytes when calculating userland buffer size. --- sys/kern/subr_iostat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_iostat.c b/sys/kern/subr_iostat.c index 5db9c75f17b4..e50d89fb87bc 100644 --- a/sys/kern/subr_iostat.c +++ b/sys/kern/subr_iostat.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_iostat.c,v 1.25 2019/05/22 08:47:02 hannken Exp $ */ +/* $NetBSD: subr_iostat.c,v 1.26 2024/05/04 13:33:18 mlelstv Exp $ */ /* NetBSD: subr_disk.c,v 1.69 2005/05/29 22:24:15 christos Exp */ /*- @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.25 2019/05/22 08:47:02 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.26 2024/05/04 13:33:18 mlelstv Exp $"); #include #include @@ -370,6 +370,8 @@ iostati_getnames(int disk_only, char *oldp, size_t *oldlenp, const void *newp, memset(bf, 0, sizeof(bf)); if (first) { strncpy(bf, stats->io_name, sizeof(bf)); + /* account for trailing NUL byte */ + needed += 1; first = 0; } else { bf[0] = ' ';