summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorcem <cem@FreeBSD.org>2016-05-12 03:44:29 +0000
committercem <cem@FreeBSD.org>2016-05-12 03:44:29 +0000
commit2274d498f72410c50ec09b3fe59f406483bda4bb (patch)
treec7cd45d03185b0e9fe1f527716ef317d07af839d /tests
parent201cd226c80fdd60aa722a14d5a6d3f44c3d3eb0 (diff)
downloadFreeBSD-src-2274d498f72410c50ec09b3fe59f406483bda4bb.zip
FreeBSD-src-2274d498f72410c50ec09b3fe59f406483bda4bb.tar.gz
kern_descrip_test: Fix trivial buffer overrun with readlink(2)
Reported by: Coverity CID: 1229965, 1229972 Sponsored by: EMC / Isilon Storage Division
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/kern/kern_descrip_test.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tests/sys/kern/kern_descrip_test.c b/tests/sys/kern/kern_descrip_test.c
index 6953b00..07240d7 100644
--- a/tests/sys/kern/kern_descrip_test.c
+++ b/tests/sys/kern/kern_descrip_test.c
@@ -27,6 +27,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/param.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -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,
OpenPOWER on IntegriCloud