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

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