autofs-5.1.8 - change to use printf functions in amd parser From: Ian Kent 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 --- CHANGELOG | 1 + modules/parse_amd.c | 45 +++++++++++++++++---------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 562ffc41..43f1c0e3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -82,6 +82,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. 19/10/2021 autofs-5.1.8 - add xdr_exports(). diff --git a/modules/parse_amd.c b/modules/parse_amd.c index e76edf31..1a46ae0d 100644 --- a/modules/parse_amd.c +++ b/modules/parse_amd.c @@ -170,11 +170,9 @@ static struct substvar *add_lookup_vars(struct autofs_point *ap, 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); @@ -1074,24 +1072,23 @@ static int do_auto_mount(struct autofs_point *ap, const char *name, 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, @@ -1214,17 +1211,15 @@ static int do_nfs_mount(struct autofs_point *ap, const char *name, 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; @@ -1326,7 +1321,7 @@ static int do_host_mount(struct autofs_point *ap, const char *name, */ if (strcmp(name, entry->rhost)) { char *target; - size_t len; + int len; len = ap->len + strlen(entry->rhost) + 2; target = malloc(len); @@ -1335,9 +1330,7 @@ static int do_host_mount(struct autofs_point *ap, const char *name, "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; @@ -1826,7 +1819,7 @@ static void normalize_sublink(unsigned int logopt, 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) @@ -1840,9 +1833,7 @@ static void normalize_sublink(unsigned int logopt, "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); @@ -1873,9 +1864,7 @@ static void update_prefix(struct autofs_point *ap, 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; } }