Author: ngie
Date: Fri Jun 10 18:07:35 2016
New Revision: 301805
URL: https://svnweb.freebsd.org/changeset/base/301805

Log:
  MFC r299508:
  r299508 (by cem):
  
  kern_descrip_test: Fix trivial buffer overrun with readlink(2)
  
  CID:          1229965, 1229972

Modified:
  stable/10/tests/sys/kern/kern_descrip_test.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/tests/sys/kern/kern_descrip_test.c
==============================================================================
--- stable/10/tests/sys/kern/kern_descrip_test.c        Fri Jun 10 18:04:54 
2016        (r301804)
+++ stable/10/tests/sys/kern/kern_descrip_test.c        Fri Jun 10 18:07:35 
2016        (r301805)
@@ -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, 
        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,
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "[email protected]"

Reply via email to