[Midnightbsd-cvs] src [8694] trunk/lib/libc/gen/check_utility_compat.c: reduce buffer size from LINE_MAX to PATH_MAX

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 18:09:55 EDT 2016


Revision: 8694
          http://svnweb.midnightbsd.org/src/?rev=8694
Author:   laffer1
Date:     2016-09-25 18:09:55 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
reduce buffer size from LINE_MAX to PATH_MAX

Modified Paths:
--------------
    trunk/lib/libc/gen/check_utility_compat.c

Modified: trunk/lib/libc/gen/check_utility_compat.c
===================================================================
--- trunk/lib/libc/gen/check_utility_compat.c	2016-09-25 22:09:30 UTC (rev 8693)
+++ trunk/lib/libc/gen/check_utility_compat.c	2016-09-25 22:09:55 UTC (rev 8694)
@@ -35,15 +35,13 @@
  * are threaded, so I'm not concerned about cancellation points or other
  * niceties.
  */
+#include <sys/limits.h>
+
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
-#ifndef LINE_MAX
-#define	LINE_MAX _POSIX2_LINE_MAX
-#endif
-
 #define	_PATH_UTIL_COMPAT	"/etc/compat-FreeBSD-4-util"
 #define	_ENV_UTIL_COMPAT	"_COMPAT_FreeBSD_4"
 
@@ -50,7 +48,7 @@
 int
 check_utility_compat(const char *utility)
 {
-	char buf[LINE_MAX];
+	char buf[PATH_MAX];
 	char *p, *bp;
 	int len;
 
@@ -57,10 +55,8 @@
 	if ((p = getenv(_ENV_UTIL_COMPAT)) != NULL) {
 		strlcpy(buf, p, sizeof buf);
 	} else {
-		if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof buf)) < 0)
+		if ((len = readlink(_PATH_UTIL_COMPAT, buf, sizeof(buf) - 1)) < 0)
 			return 0;
-		if (len > sizeof buf)
-			len = sizeof buf;
 		buf[len] = '\0';
 	}
 	if (buf[0] == '\0')



More information about the Midnightbsd-cvs mailing list