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

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