autofs/SOURCES/autofs-5.1.8-fix-sysconf-return-handling.patch
2022-03-30 15:40:13 +00:00

65 lines
1.7 KiB
Diff

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