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

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