autofs/autofs-5.1.8-change-to-use-printf-functions-in-amd-parser.patch
2023-06-13 10:51:59 +08:00

145 lines
4.2 KiB
Diff

autofs-5.1.8 - change to use printf functions in amd parser
From: Ian Kent <raven@themaw.net>
Change to use the printf(3) functions in the amd parser rather than
string functions. These functions seem to have less overhead and they
are a little more compact.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1 +
modules/parse_amd.c | 45 +++++++++++++++++----------------------------
2 files changed, 18 insertions(+), 28 deletions(-)
--- autofs-5.1.4.orig/CHANGELOG
+++ autofs-5.1.4/CHANGELOG
@@ -137,6 +137,7 @@
- get rid of strlen call in handle_packet_missing_direct().
- remove redundant stat call in lookup_ghost().
- set mapent dev and ino before adding to index.
+- change to use printf functions in amd parser.
xx/xx/2018 autofs-5.1.5
- fix flag file permission.
--- autofs-5.1.4.orig/modules/parse_amd.c
+++ autofs-5.1.4/modules/parse_amd.c
@@ -170,11 +170,9 @@ static struct substvar *add_lookup_vars(
if (*key == '/')
strcpy(path, key);
- else {
- strcpy(path, ap->path);
- strcat(path, "/");
- strcat(path, key);
- }
+ else
+ sprintf(path, "%s/%s", ap->path, key);
+
list = macro_addvar(list, "path", 4, path);
me = cache_lookup_distinct(source->mc, lkp_key);
@@ -1067,24 +1065,23 @@ static int do_auto_mount(struct autofs_p
struct amd_entry *entry, unsigned int flags)
{
char target[PATH_MAX + 1];
+ int len;
if (!entry->map_type) {
- if (strlen(entry->fs) > PATH_MAX) {
+ len = snprintf(target, PATH_MAX, "%s", entry->fs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: fs option length is too long");
return 0;
}
- strcpy(target, entry->fs);
} else {
- if (strlen(entry->fs) +
- strlen(entry->map_type) + 5 > PATH_MAX) {
+ len = snprintf(target, PATH_MAX,
+ "%s,amd:%s", entry->map_type, entry->fs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: fs + maptype options length is too long");
return 0;
}
- strcpy(target, entry->map_type);
- strcat(target, ",amd:");
- strcat(target, entry->fs);
}
return do_mount(ap, ap->path,
@@ -1207,17 +1204,15 @@ static int do_nfs_mount(struct autofs_po
char *opts = (entry->opts && *entry->opts) ? entry->opts : NULL;
unsigned int umount = 0;
int ret = 0;
+ int len;
- if (strlen(entry->rhost) + strlen(entry->rfs) + 1 > PATH_MAX) {
+ len = snprintf(target, PATH_MAX, "%s:%s", entry->rhost, entry->rfs);
+ if (len > PATH_MAX) {
error(ap->logopt, MODPREFIX
"error: rhost + rfs options length is too long");
return 1;
}
- strcpy(target, entry->rhost);
- strcat(target, ":");
- strcat(target, entry->rfs);
-
proximity = get_network_proximity(entry->rhost);
if (proximity == PROXIMITY_OTHER && entry->remopts && *entry->remopts)
opts = entry->remopts;
@@ -1319,7 +1314,7 @@ static int do_host_mount(struct autofs_p
*/
if (strcmp(name, entry->rhost)) {
char *target;
- size_t len;
+ int len;
len = ap->len + strlen(entry->rhost) + 2;
target = malloc(len);
@@ -1328,9 +1323,7 @@ static int do_host_mount(struct autofs_p
"failed to alloc target to hosts mount base");
goto out;
}
- strcpy(target, ap->path);
- strcat(target, "/");
- strcat(target, entry->rhost);
+ sprintf(target, "%s/%s", ap->path, entry->rhost);
if (entry->path)
free(entry->path);
entry->path = target;
@@ -1819,7 +1812,7 @@ static void normalize_sublink(unsigned i
struct amd_entry *entry, struct substvar *sv)
{
char *new;
- size_t len;
+ int len;
/* Normalizing sublink requires a non-blank fs option */
if (!*entry->fs)
@@ -1833,9 +1826,7 @@ static void normalize_sublink(unsigned i
"error: couldn't allocate storage for sublink");
return;
}
- strcpy(new, entry->fs);
- strcat(new, "/");
- strcat(new, entry->sublink);
+ sprintf(new, "%s/%s", entry->fs, entry->sublink);
debug(logopt, MODPREFIX
"rfs dequote(\"%.*s\") -> %s",
strlen(entry->sublink), entry->sublink, new);
@@ -1866,9 +1857,7 @@ static void update_prefix(struct autofs_
len = strlen(ap->pref) + strlen(name) + 2;
new = malloc(len);
if (new) {
- strcpy(new, ap->pref);
- strcat(new, name);
- strcat(new, "/");
+ sprintf(new, "%s%s/", ap->pref, name);
entry->pref = new;
}
}