Blame SOURCES/autofs-5.1.7-eliminate-some-more-alloca-usage.patch

96dc52
autofs-5.1.7 - eliminate some more alloca usage
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Quite a bit of the alloca(3) usage has been eliminated over time.
96dc52
Use malloc(3) for some more cases that might need to allocate a largish
96dc52
amount of storage.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
96dc52
autofs-5.1.7 - eliminate some more alloca usage
96dc52
96dc52
From: Ian Kent <raven@themaw.net>
96dc52
96dc52
Quite a bit of the alloca(3) usage has been eliminated over time.
96dc52
Use malloc(3) for some more cases that might need to allocate a largish
96dc52
amount of storage.
96dc52
96dc52
Signed-off-by: Ian Kent <raven@themaw.net>
96dc52
---
96dc52
 CHANGELOG                |    1 +
96dc52
 modules/lookup_program.c |   11 ++++++++++-
96dc52
 modules/lookup_yp.c      |   22 +++++++++++++++++++---
96dc52
 modules/parse_sun.c      |   18 ++++++++++++++----
96dc52
 modules/replicated.c     |   19 ++++++-------------
96dc52
 5 files changed, 50 insertions(+), 21 deletions(-)
96dc52
96dc52
--- autofs-5.1.7.orig/CHANGELOG
96dc52
+++ autofs-5.1.7/CHANGELOG
96dc52
@@ -78,6 +78,7 @@
96dc52
 - add missing description of null map option.
96dc52
 - fix nonstrict offset mount fail handling.
96dc52
 - fix concat_options() error handling.
96dc52
+- eliminate some more alloca usage.
96dc52
 
96dc52
 25/01/2021 autofs-5.1.7
96dc52
 - make bind mounts propagation slave by default.
96dc52
--- autofs-5.1.7.orig/modules/lookup_program.c
96dc52
+++ autofs-5.1.7/modules/lookup_program.c
96dc52
@@ -636,7 +636,14 @@ int lookup_mount(struct autofs_point *ap
96dc52
 			char *ent = NULL;
96dc52
 
96dc52
 			if (me->mapent) {
96dc52
-				ent = alloca(strlen(me->mapent) + 1);
96dc52
+				ent = malloc(strlen(me->mapent) + 1);
96dc52
+				if (!ent) {
96dc52
+					char buf[MAX_ERR_BUF];
96dc52
+					char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
+					error(ap->logopt, MODPREFIX "malloc: %s", estr);
96dc52
+					cache_unlock(mc);
96dc52
+					goto out_free;
96dc52
+				}
96dc52
 				strcpy(ent, me->mapent);
96dc52
 			}
96dc52
 			cache_unlock(mc);
96dc52
@@ -644,6 +651,8 @@ int lookup_mount(struct autofs_point *ap
96dc52
 			ap->entry->current = source;
96dc52
 			ret = ctxt->parse->parse_mount(ap, name,
96dc52
 				 name_len, ent, ctxt->parse->context);
96dc52
+			if (ent)
96dc52
+				free(ent);
96dc52
 			goto out_free;
96dc52
 		} else {
96dc52
 			if (IS_MM(me) && !IS_MM_ROOT(me)) {
96dc52
--- autofs-5.1.7.orig/modules/lookup_yp.c
96dc52
+++ autofs-5.1.7/modules/lookup_yp.c
96dc52
@@ -254,7 +254,7 @@ int yp_all_master_callback(int status, c
96dc52
 
96dc52
 	len = ypkeylen + 1 + vallen + 2;
96dc52
 
96dc52
-	buffer = alloca(len);
96dc52
+	buffer = malloc(len);
96dc52
 	if (!buffer) {
96dc52
 		error(logopt, MODPREFIX "could not malloc parse buffer");
96dc52
 		return 0;
96dc52
@@ -267,6 +267,8 @@ int yp_all_master_callback(int status, c
96dc52
 
96dc52
 	master_parse_entry(buffer, timeout, logging, age);
96dc52
 
96dc52
+	free(buffer);
96dc52
+
96dc52
 	return 0;
96dc52
 }
96dc52
 
96dc52
@@ -368,7 +370,12 @@ int yp_all_callback(int status, char *yp
96dc52
 		return 0;
96dc52
 	}
96dc52
 
96dc52
-	mapent = alloca(vallen + 1);
96dc52
+	mapent = malloc(vallen + 1);
96dc52
+	if (!mapent) {
96dc52
+		error(logopt, MODPREFIX "could not malloc mapent buffer");
96dc52
+		free(key);
96dc52
+		return 0;
96dc52
+	}
96dc52
 	strncpy(mapent, val, vallen);
96dc52
 	*(mapent + vallen) = '\0';
96dc52
 
96dc52
@@ -377,6 +384,7 @@ int yp_all_callback(int status, char *yp
96dc52
 	cache_unlock(mc);
96dc52
 
96dc52
 	free(key);
96dc52
+	free(mapent);
96dc52
 
96dc52
 	if (ret == CHE_FAIL)
96dc52
 		return -1;
96dc52
@@ -904,7 +912,14 @@ int lookup_mount(struct autofs_point *ap
96dc52
 		}
96dc52
 		if (me && (me->source == source || *me->key == '/')) {
96dc52
 			mapent_len = strlen(me->mapent);
96dc52
-			mapent = alloca(mapent_len + 1);
96dc52
+			mapent = malloc(mapent_len + 1);
96dc52
+			if (!mapent) {
96dc52
+				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
+				error(ap->logopt, MODPREFIX "malloc: %s", estr);
96dc52
+				cache_unlock(mc);
96dc52
+				free(lkp_key);
96dc52
+				return NSS_STATUS_TRYAGAIN;
96dc52
+			}
96dc52
 			strcpy(mapent, me->mapent);
96dc52
 		}
96dc52
 	}
96dc52
@@ -929,6 +944,7 @@ int lookup_mount(struct autofs_point *ap
96dc52
 
96dc52
 	ret = ctxt->parse->parse_mount(ap, key, key_len,
96dc52
 				       mapent, ctxt->parse->context);
96dc52
+	free(mapent);
96dc52
 	if (ret) {
96dc52
 		/* Don't update negative cache when re-connecting */
96dc52
 		if (ap->flags & MOUNT_FLAG_REMOUNT)
96dc52
--- autofs-5.1.7.orig/modules/parse_sun.c
96dc52
+++ autofs-5.1.7/modules/parse_sun.c
96dc52
@@ -668,9 +668,16 @@ static int sun_mount(struct autofs_point
96dc52
 		}
96dc52
 	}
96dc52
 
96dc52
+	what = malloc(loclen + 1);
96dc52
+	if (!what) {
96dc52
+		char buf[MAX_ERR_BUF];
96dc52
+		char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
96dc52
+		error(ap->logopt, MODPREFIX "malloc: %s", estr);
96dc52
+		return 1;
96dc52
+	}
96dc52
+
96dc52
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
96dc52
 	if (!strcmp(fstype, "nfs") || !strcmp(fstype, "nfs4")) {
96dc52
-		what = alloca(loclen + 1);
96dc52
 		memcpy(what, loc, loclen);
96dc52
 		what[loclen] = '\0';
96dc52
 
96dc52
@@ -706,10 +713,10 @@ static int sun_mount(struct autofs_point
96dc52
 		rv = mount_nfs->mount_mount(ap, root, name, namelen,
96dc52
 					    what, fstype, options, mount_nfs->context);
96dc52
 	} else {
96dc52
-		if (!loclen)
96dc52
+		if (!loclen) {
96dc52
+			free(what);
96dc52
 			what = NULL;
96dc52
-		else {
96dc52
-			what = alloca(loclen + 1);
96dc52
+		} else {
96dc52
 			if (*loc == ':') {
96dc52
 				loclen--;
96dc52
 				memcpy(what, loc + 1, loclen);
96dc52
@@ -728,6 +735,9 @@ static int sun_mount(struct autofs_point
96dc52
 		/* Generic mount routine */
96dc52
 		rv = do_mount(ap, root, name, namelen, what, fstype, options);
96dc52
 	}
96dc52
+	if (what)
96dc52
+		free(what);
96dc52
+
96dc52
 	pthread_setcancelstate(cur_state, NULL);
96dc52
 
96dc52
 	if (nonstrict && rv)
96dc52
--- autofs-5.1.7.orig/modules/replicated.c
96dc52
+++ autofs-5.1.7/modules/replicated.c
96dc52
@@ -1041,25 +1041,18 @@ done:
96dc52
 	return ret;
96dc52
 }
96dc52
 
96dc52
-static int add_path(struct host *hosts, const char *path, int len)
96dc52
+static int add_path(struct host *hosts, const char *path)
96dc52
 {
96dc52
 	struct host *this;
96dc52
-	char *tmp, *tmp2;
96dc52
-
96dc52
-	tmp = alloca(len + 1);
96dc52
-	if (!tmp)
96dc52
-		return 0;
96dc52
-
96dc52
-	strncpy(tmp, path, len);
96dc52
-	tmp[len] = '\0';
96dc52
+	char *tmp;
96dc52
 
96dc52
 	this = hosts;
96dc52
 	while (this) {
96dc52
 		if (!this->path) {
96dc52
-			tmp2 = strdup(tmp);
96dc52
-			if (!tmp2)
96dc52
+			tmp = strdup(path);
96dc52
+			if (!tmp)
96dc52
 				return 0;
96dc52
-			this->path = tmp2;
96dc52
+			this->path = tmp;
96dc52
 		}
96dc52
 		this = this->next;
96dc52
 	}
96dc52
@@ -1188,7 +1181,7 @@ int parse_location(unsigned logopt, stru
96dc52
 						}
96dc52
 					}
96dc52
 
96dc52
-					if (!add_path(*hosts, path, strlen(path))) {
96dc52
+					if (!add_path(*hosts, path)) {
96dc52
 						free_host_list(hosts);
96dc52
 						free(str);
96dc52
 						return 0;