From 079375d12b46e5ced7ac96618f4a6a0c13055eae Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Thu, 12 May 2016 03:44:29 +0000 Subject: [PATCH] kern_descrip_test: Fix trivial buffer overrun with readlink(2) Reported by: Coverity CID: 1229965, 1229972 Sponsored by: EMC / Isilon Storage Division --- tests/sys/kern/kern_descrip_test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/sys/kern/kern_descrip_test.c b/tests/sys/kern/kern_descrip_test.c index 6953b00fc6f2..07240d75b900 100644 --- a/tests/sys/kern/kern_descrip_test.c +++ b/tests/sys/kern/kern_descrip_test.c @@ -27,6 +27,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -170,7 +171,7 @@ ATF_TC_CLEANUP(kern_maxfiles__increase, tc) char buf[80]; if ((n = readlink(VALUE, buf, sizeof(buf))) > 0) { - buf[n] = '\0'; + buf[MIN((size_t)n, sizeof(buf) - 1)] = '\0'; if (sscanf(buf, "%d", &oldmaxfiles) == 1) { oldlen = sizeof(oldmaxfiles); (void) sysctlbyname("kern.maxfiles", NULL, 0,