Blame SOURCES/autofs-5.1.7-use-sprintf-when-constructing-hosts-mapent.patch

29d2b9
autofs-5.1.7 - use snprintf() when constructing hosts mapent
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Using multiple strcpy() and strcat() functions when constructing the
29d2b9
hosts map offset for each export is much slower than using a single
29d2b9
sprintf() for each.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG              |    1 +
29d2b9
 modules/lookup_hosts.c |   26 +++++++++++++-------------
29d2b9
 2 files changed, 14 insertions(+), 13 deletions(-)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index 1bd6ac7f..d613e5ca 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -2,6 +2,7 @@
29d2b9
 - add xdr_exports().
29d2b9
 - remove mount.x and rpcgen dependencies.
29d2b9
 - dont use realloc in host exports list processing.
29d2b9
+- use sprintf() when constructing hosts mapent.
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c
29d2b9
index e3ee0ab8..c1ebb7f6 100644
29d2b9
--- a/modules/lookup_hosts.c
29d2b9
+++ b/modules/lookup_hosts.c
29d2b9
@@ -87,10 +87,12 @@ int lookup_read_master(struct master *master, time_t age, void *context)
29d2b9
 static char *get_exports(struct autofs_point *ap, const char *host)
29d2b9
 {
29d2b9
 	char buf[MAX_ERR_BUF];
29d2b9
+	char entry[PATH_MAX + 1];
29d2b9
 	char *mapent;
29d2b9
 	struct exportinfo *exp, *this;
29d2b9
 	size_t hostlen = strlen(host);
29d2b9
 	size_t mapent_len;
29d2b9
+	int len, pos;
29d2b9
 
29d2b9
 	debug(ap->logopt, MODPREFIX "fetchng export list for %s", host);
29d2b9
 
29d2b9
@@ -114,21 +116,19 @@ static char *get_exports(struct autofs_point *ap, const char *host)
29d2b9
 	}
29d2b9
 	*mapent = 0;
29d2b9
 
29d2b9
+	pos = 0;
29d2b9
 	this = exp;
29d2b9
-	while (this) {
29d2b9
-		if (!*mapent)
29d2b9
-			strcpy(mapent, "\"");
29d2b9
-		else
29d2b9
-			strcat(mapent, " \"");
29d2b9
-		strcat(mapent, this->dir);
29d2b9
-		strcat(mapent, "\"");
29d2b9
-
29d2b9
-		strcat(mapent, " \"");
29d2b9
-		strcat(mapent, host);
29d2b9
-		strcat(mapent, ":");
29d2b9
-		strcat(mapent, this->dir);
29d2b9
-		strcat(mapent, "\"");
29d2b9
+	if (this) {
29d2b9
+		len = sprintf(mapent, "\"%s\" \"%s:%s\"",
29d2b9
+				this->dir, host, this->dir);
29d2b9
+		pos += len;
29d2b9
+		this = this->next;
29d2b9
+	}
29d2b9
 
29d2b9
+	while (this) {
29d2b9
+		len = sprintf(mapent + pos, " \"%s\" \"%s:%s\"",
29d2b9
+				this->dir, host, this->dir);
29d2b9
+		pos += len;
29d2b9
 		this = this->next;
29d2b9
 	}
29d2b9
 	rpc_exports_free(exp);