Blame SOURCES/autofs-5.1.7-fix-concat_options-error-handling.patch

96dc52
autofs-5.1.7 - fix concat_options() error handling
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
There's a possibility of a memory leak in the mount options processing
96dc52
when calling concat_options() in parse_mount() of the Sun format map
96dc52
entry parsing.
96dc52
96dc52
There's also a case in do_init() of the Sun map format parsing where
96dc52
a previously freed value is used in a logging statement without being
96dc52
set to MULL.
96dc52
96dc52
So ensure concat_options() always frees it's arguments so that the
96dc52
handling can be consistent in all places.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG           |    1 +
96dc52
 modules/parse_sun.c |   24 +++++++++++-------------
96dc52
 2 files changed, 12 insertions(+), 13 deletions(-)
96dc52
96dc52
--- autofs-5.1.7.orig/CHANGELOG
96dc52
+++ autofs-5.1.7/CHANGELOG
96dc52
@@ -77,6 +77,7 @@
96dc52
 - fix lookup_prune_one_cache() refactoring change.
96dc52
 - add missing description of null map option.
96dc52
 - fix nonstrict offset mount fail handling.
96dc52
+- fix concat_options() error handling.
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
--- autofs-5.1.7.orig/modules/parse_sun.c
96dc52
+++ autofs-5.1.7/modules/parse_sun.c
96dc52
@@ -380,7 +380,8 @@ static int do_init(int argc, const char
96dc52
 			if (!tmp) {
96dc52
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
 				logerr(MODPREFIX "concat_options: %s", estr);
96dc52
-				free(gbl_options);
96dc52
+				/* freed in concat_options */
96dc52
+				ctxt->optstr = NULL;
96dc52
 			} else
96dc52
 				ctxt->optstr = tmp;
96dc52
 		} else {
96dc52
@@ -492,12 +493,16 @@ static char *concat_options(char *left,
96dc52
 	char *ret;
96dc52
 
96dc52
 	if (left == NULL || *left == '\0') {
96dc52
+		if (!right || *right == '\0')
96dc52
+			return NULL;
96dc52
 		ret = strdup(right);
96dc52
 		free(right);
96dc52
 		return ret;
96dc52
 	}
96dc52
 
96dc52
 	if (right == NULL || *right == '\0') {
96dc52
+		if (left == NULL || *left == '\0')
96dc52
+			return NULL;
96dc52
 		ret = strdup(left);
96dc52
 		free(left);
96dc52
 		return ret;
96dc52
@@ -508,6 +513,8 @@ static char *concat_options(char *left,
96dc52
 	if (ret == NULL) {
96dc52
 		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
 		logerr(MODPREFIX "malloc: %s", estr);
96dc52
+		free(left);
96dc52
+		free(right);
96dc52
 		return NULL;
96dc52
 	}
96dc52
 
96dc52
@@ -989,14 +996,13 @@ static int parse_mapent(const char *ent,
96dc52
 			if (newopt && strstr(newopt, myoptions)) {
96dc52
 				free(myoptions);
96dc52
 				myoptions = newopt;
96dc52
-			} else {
96dc52
+			} else if (newopt) {
96dc52
 				tmp = concat_options(myoptions, newopt);
96dc52
 				if (!tmp) {
96dc52
 					char *estr;
96dc52
 					estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
 					error(logopt, MODPREFIX
96dc52
 					      "concat_options: %s", estr);
96dc52
-					free(myoptions);
96dc52
 					return 0;
96dc52
 				}
96dc52
 				myoptions = tmp;
96dc52
@@ -1358,16 +1364,12 @@ dont_expand:
96dc52
 			if (mnt_options && noptions && strstr(noptions, mnt_options)) {
96dc52
 				free(mnt_options);
96dc52
 				mnt_options = noptions;
96dc52
-			} else {
96dc52
+			} else if (noptions) {
96dc52
 				tmp = concat_options(mnt_options, noptions);
96dc52
 				if (!tmp) {
96dc52
 					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
 					error(ap->logopt,
96dc52
 					      MODPREFIX "concat_options: %s", estr);
96dc52
-					if (noptions)
96dc52
-						free(noptions);
96dc52
-					if (mnt_options)
96dc52
-						free(mnt_options);
96dc52
 					free(options);
96dc52
 					free(pmapent);
96dc52
 					return 1;
96dc52
@@ -1387,15 +1389,11 @@ dont_expand:
96dc52
 			if (options && mnt_options && strstr(mnt_options, options)) {
96dc52
 				free(options);
96dc52
 				options = mnt_options;
96dc52
-			} else {
96dc52
+			} else if (mnt_options) {
96dc52
 				tmp = concat_options(options, mnt_options);
96dc52
 				if (!tmp) {
96dc52
 					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
 					error(ap->logopt, MODPREFIX "concat_options: %s", estr);
96dc52
-					if (options)
96dc52
-						free(options);
96dc52
-					if (mnt_options)
96dc52
-						free(mnt_options);
96dc52
 					free(pmapent);
96dc52
 					return 1;
96dc52
 				}