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

77 lines
2.0 KiB
Diff
Raw Normal View History

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