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

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