Blame SOURCES/autofs-5.1.8-fix-sysconf-return-handling.patch

f3080c
autofs-5.1.8 - fix sysconf(3) return handling
f3080c
f3080c
From: Fabian Groffen <grobian@gentoo.org>
f3080c
f3080c
The sysconf(3) return handling doesn't handle a -1 return with errno
f3080c
not changed which indicated a maximum or minimum limit that's not
f3080c
known.
f3080c
f3080c
Add handling of this case.
f3080c
f3080c
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
f3080c
Signed-off-by: Ian Kent <raven@themaw.net>
f3080c
---
f3080c
 CHANGELOG    |    1 +
f3080c
 lib/mounts.c |   13 +++++++++++--
f3080c
 2 files changed, 12 insertions(+), 2 deletions(-)
f3080c
f3080c
--- autofs-5.1.4.orig/CHANGELOG
f3080c
+++ autofs-5.1.4/CHANGELOG
f3080c
@@ -91,6 +91,7 @@
f3080c
 - fix use after free in tree_mapent_delete_offset_tree().
f3080c
 - fix memory leak in xdr_exports().
f3080c
 - avoid calling pthread_getspecific() with NULL key_thread_attempt_id.
f3080c
+- fix sysconf(3) return handling.
f3080c
 
f3080c
 xx/xx/2018 autofs-5.1.5
f3080c
 - fix flag file permission.
f3080c
--- autofs-5.1.4.orig/lib/mounts.c
f3080c
+++ autofs-5.1.4/lib/mounts.c
f3080c
@@ -2385,11 +2385,17 @@ void set_tsd_user_vars(unsigned int logo
f3080c
 
f3080c
 	/* Try to get passwd info */
f3080c
 
f3080c
+	/* sysconf may return -1 with unchanged errno to indicate unlimited
f3080c
+	 * size, same for the call for _SC_GETGR_R_SIZE_MAX  below
f3080c
+	 */
f3080c
+	errno = 0;
f3080c
 	tmplen = sysconf(_SC_GETPW_R_SIZE_MAX);
f3080c
-	if (tmplen < 0) {
f3080c
+	if (tmplen < 0 && errno != 0) {
f3080c
 		error(logopt, "failed to get buffer size for getpwuid_r");
f3080c
 		goto free_tsv;
f3080c
 	}
f3080c
+	if (tmplen < 0)
f3080c
+		tmplen = 1024;	/* assume something reasonable */
f3080c
 
f3080c
 	pw_tmp = malloc(tmplen + 1);
f3080c
 	if (!pw_tmp) {
f3080c
@@ -2422,11 +2428,14 @@ void set_tsd_user_vars(unsigned int logo
f3080c
 
f3080c
 	/* Try to get group info */
f3080c
 
f3080c
+	errno = 0;
f3080c
 	grplen = sysconf(_SC_GETGR_R_SIZE_MAX);
f3080c
-	if (grplen < 0) {
f3080c
+	if (grplen < 0 && errno != 0) {
f3080c
 		error(logopt, "failed to get buffer size for getgrgid_r");
f3080c
 		goto free_tsv_home;
f3080c
 	}
f3080c
+	if (grplen < 0)
f3080c
+		grplen = 1024;
f3080c
 
f3080c
 	gr_tmp = NULL;
f3080c
 	status = ERANGE;