1 autofs-5.0.4 - easy alloca replacements
3 From: Valerie Aurora Henson <vaurora@redhat.com>
5 alloca() is compiler-dependent, non-standard, and has undefined
6 behavior when it fails (IOW, the program crashes). Replace with
7 normal C stack variables where possible and malloc() where not.
10 daemon/automount.c | 29 ++++++--------
11 daemon/direct.c | 12 ++----
12 daemon/flag.c | 13 +++---
13 daemon/indirect.c | 12 ++----
14 daemon/module.c | 45 +++++++---------------
15 lib/cache.c | 31 +++++----------
17 modules/lookup_file.c | 82 +++++++++++++----------------------------
18 modules/lookup_ldap.c | 93 +++++++++++++++++++++++++++++-----------------
19 modules/lookup_nisplus.c | 71 ++++++++++++++++++++---------------
20 modules/mount_autofs.c | 1
21 modules/mount_bind.c | 7 +--
22 modules/mount_changer.c | 5 --
23 modules/mount_ext2.c | 5 --
24 modules/mount_generic.c | 5 --
25 15 files changed, 184 insertions(+), 228 deletions(-)
28 diff --git a/daemon/automount.c b/daemon/automount.c
29 index e20e7c9..269fc5b 100644
30 --- a/daemon/automount.c
31 +++ b/daemon/automount.c
32 @@ -127,8 +127,8 @@ static int do_mkdir(const char *parent, const char *path, mode_t mode)
34 int mkdir_path(const char *path, mode_t mode)
36 - char *buf = alloca(strlen(path) + 1);
37 - char *parent = alloca(strlen(path) + 1);
39 + char parent[PATH_MAX];
40 const char *cp = path, *lcp = path;
41 char *bp = buf, *pp = parent;
43 @@ -163,7 +163,7 @@ int mkdir_path(const char *path, mode_t mode)
44 int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev)
46 int len = strlen(path);
47 - char *buf = alloca(len + 1);
52 @@ -468,20 +468,17 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
53 pthread_cleanup_push(cache_lock_cleanup, mc);
58 + char root[PATH_MAX];
62 - ap_len = strlen(ap->path);
64 - if (!strchr(me->multi->key, '/')) {
65 + if (!strchr(me->multi->key, '/'))
66 /* Indirect multi-mount root */
67 - root = alloca(ap_len + strlen(me->multi->key) + 2);
68 - strcpy(root, ap->path);
70 - strcat(root, me->multi->key);
72 - root = me->multi->key;
73 + /* sprintf okay - if it's mounted, it's
74 + * PATH_MAX or less bytes */
75 + sprintf(root, "%s/%s", ap->path, me->multi->key);
77 + strcpy(root, me->multi->key);
81 @@ -929,14 +926,14 @@ static int get_pkt(struct autofs_point *ap, union autofs_v5_packet_union *pkt)
83 int do_expire(struct autofs_point *ap, const char *name, int namelen)
85 - char buf[PATH_MAX + 1];
90 len = ncat_path(buf, sizeof(buf), ap->path, name, namelen);
92 len = snprintf(buf, PATH_MAX, "%s", name);
94 + if (len >= PATH_MAX)
98 diff --git a/daemon/direct.c b/daemon/direct.c
99 index fc3c969..4f4ff20 100644
100 --- a/daemon/direct.c
101 +++ b/daemon/direct.c
102 @@ -637,7 +637,9 @@ int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *
103 time_t timeout = ap->exp_timeout;
105 int ioctlfd, status, ret;
106 - const char *type, *map_name = NULL;
107 + const char *hosts_map_name = "-hosts";
108 + const char *map_name = hosts_map_name;
110 char mountpoint[PATH_MAX];
112 if (ops->version && ap->flags & MOUNT_FLAG_REMOUNT) {
113 @@ -740,13 +742,7 @@ int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *
114 mp->options, mountpoint);
116 type = ap->entry->maps->type;
117 - if (type && !strcmp(ap->entry->maps->type, "hosts")) {
118 - char *tmp = alloca(7);
120 - strcpy(tmp, "-hosts");
121 - map_name = (const char *) tmp;
124 + if (!type || strcmp(ap->entry->maps->type, "hosts"))
125 map_name = me->mc->map->argv[0];
127 ret = mount(map_name, mountpoint, "autofs", MS_MGC_VAL, mp->options);
128 diff --git a/daemon/flag.c b/daemon/flag.c
129 index e43cece..f8fe163 100644
133 #include <sys/stat.h>
142 #include "automount.h"
144 @@ -113,12 +113,13 @@ void release_flag_file(void)
145 /* * Try to create flag file */
146 int aquire_flag_file(void)
150 + char linkf[PATH_MAX];
153 - len = strlen(FLAG_FILE) + MAX_PIDSIZE;
154 - linkf = alloca(len + 1);
155 - snprintf(linkf, len, "%s.%d", FLAG_FILE, getpid());
156 + len = snprintf(linkf, sizeof(linkf), "%s.%d", FLAG_FILE, getpid());
157 + if (len >= sizeof(linkf))
158 + /* Didn't acquire it */
162 * Repeat until it was us who made the link or we find the
163 diff --git a/daemon/indirect.c b/daemon/indirect.c
164 index f40c393..2539282 100644
165 --- a/daemon/indirect.c
166 +++ b/daemon/indirect.c
167 @@ -90,7 +90,9 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)
168 struct ioctl_ops *ops = get_ioctl_ops();
169 time_t timeout = ap->exp_timeout;
170 char *options = NULL;
171 - const char *type, *map_name = NULL;
172 + const char *hosts_map_name = "-hosts";
173 + const char *map_name = hosts_map_name;
176 struct mnt_list *mnts;
178 @@ -142,13 +144,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)
181 type = ap->entry->maps->type;
182 - if (type && !strcmp(ap->entry->maps->type, "hosts")) {
183 - char *tmp = alloca(7);
185 - strcpy(tmp, "-hosts");
186 - map_name = (const char *) tmp;
189 + if (!type || strcmp(ap->entry->maps->type, "hosts"))
190 map_name = ap->entry->maps->argv[0];
192 ret = mount(map_name, root, "autofs", MS_MGC_VAL, options);
193 diff --git a/daemon/module.c b/daemon/module.c
194 index e593d75..466d8d7 100644
195 --- a/daemon/module.c
196 +++ b/daemon/module.c
197 @@ -58,15 +58,11 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
199 struct lookup_mod *mod;
200 char buf[MAX_ERR_BUF];
204 + char fnbuf[PATH_MAX];
209 - size_name = _strlen(name, PATH_MAX + 1);
213 mod = malloc(sizeof(struct lookup_mod));
215 @@ -77,9 +73,9 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
219 - size_fnbuf = size_name + strlen(AUTOFS_LIB_DIR) + 13;
220 - fnbuf = alloca(size_fnbuf);
222 + size = snprintf(fnbuf, sizeof(fnbuf),
223 + "%s/lookup_%s.so", AUTOFS_LIB_DIR, name);
224 + if (size >= sizeof(fnbuf)) {
227 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
228 @@ -87,7 +83,6 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
232 - snprintf(fnbuf, size_fnbuf, "%s/lookup_%s.so", AUTOFS_LIB_DIR, name);
234 if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
236 @@ -141,15 +136,11 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
238 struct parse_mod *mod;
239 char buf[MAX_ERR_BUF];
243 + char fnbuf[PATH_MAX];
248 - size_name = _strlen(name, PATH_MAX + 1);
252 mod = malloc(sizeof(struct parse_mod));
254 @@ -160,9 +151,9 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
258 - size_fnbuf = size_name + strlen(AUTOFS_LIB_DIR) + 13;
259 - fnbuf = alloca(size_fnbuf);
261 + size = snprintf(fnbuf, sizeof(fnbuf),
262 + "%s/parse_%s.so", AUTOFS_LIB_DIR, name);
263 + if (size >= sizeof(fnbuf)) {
266 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
267 @@ -170,7 +161,6 @@ struct parse_mod *open_parse(const char *name, const char *err_prefix,
271 - snprintf(fnbuf, size_fnbuf, "%s/parse_%s.so", AUTOFS_LIB_DIR, name);
273 if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
275 @@ -222,15 +212,11 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
277 struct mount_mod *mod;
278 char buf[MAX_ERR_BUF];
282 + char fnbuf[PATH_MAX];
287 - size_name = _strlen(name, PATH_MAX + 1);
291 mod = malloc(sizeof(struct mount_mod));
293 @@ -241,9 +227,9 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
297 - size_fnbuf = size_name + strlen(AUTOFS_LIB_DIR) + 13;
298 - fnbuf = alloca(size_fnbuf);
300 + size = snprintf(fnbuf, sizeof(fnbuf),
301 + "%s/mount_%s.so", AUTOFS_LIB_DIR, name);
302 + if (size >= sizeof(fnbuf)) {
305 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
306 @@ -251,7 +237,6 @@ struct mount_mod *open_mount(const char *name, const char *err_prefix)
310 - snprintf(fnbuf, size_fnbuf, "%s/mount_%s.so", AUTOFS_LIB_DIR, name);
312 if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
314 diff --git a/lib/cache.c b/lib/cache.c
315 index 4cb4582..cd62ac2 100644
318 @@ -482,27 +482,23 @@ struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int s
322 - int plen = strlen(prefix);
324 + /* Keys for direct maps may be as long as a path name */
325 + char o_key[PATH_MAX];
326 + /* Avoid "//" at the beginning of paths */
327 + const char *path_prefix = strlen(prefix) > 1 ? prefix : "";
330 /* root offset duplicates "/" */
332 - o_key = alloca(plen + strlen(offset) + 1);
333 - strcpy(o_key, prefix);
334 - strcat(o_key, offset);
336 - o_key = alloca(strlen(offset) + 1);
337 - strcpy(o_key, offset);
339 + size = snprintf(o_key, sizeof(o_key), "%s%s", path_prefix, offset);
340 + if (size >= sizeof(o_key))
343 list_for_each(p, head) {
344 this = list_entry(p, struct mapent, multi_list);
345 if (!strcmp(&this->key[start], o_key))
355 /* cache must be read locked by caller */
356 @@ -759,13 +755,8 @@ int cache_delete(struct mapent_cache *mc, const char *key)
357 struct mapent *me = NULL, *pred;
358 u_int32_t hashval = hash(key, mc->size);
359 int status, ret = CHE_OK;
361 + char this[PATH_MAX];
363 - this = alloca(strlen(key) + 1);
370 me = mc->hash[hashval];
371 diff --git a/lib/cat_path.c b/lib/cat_path.c
372 index 576b424..60669db 100644
377 * ----------------------------------------------------------------------- */
383 diff --git a/modules/lookup_file.c b/modules/lookup_file.c
384 index aafeb8b..ba80f2a 100644
385 --- a/modules/lookup_file.c
386 +++ b/modules/lookup_file.c
387 @@ -378,8 +378,8 @@ int lookup_read_master(struct master *master, time_t age, void *context)
388 unsigned int logopt = master->logopt;
393 + char path[KEY_MAX_LEN + 1];
394 + char ent[MAPENT_MAX_LEN + 1];
396 unsigned int path_len, ent_len;
397 int entry, cur_state;
398 @@ -393,20 +393,6 @@ int lookup_read_master(struct master *master, time_t age, void *context)
399 return NSS_STATUS_UNAVAIL;
402 - path = alloca(KEY_MAX_LEN + 1);
405 - MODPREFIX "could not malloc storage for path");
406 - return NSS_STATUS_UNAVAIL;
409 - ent = alloca(MAPENT_MAX_LEN + 1);
412 - MODPREFIX "could not malloc storage for mapent");
413 - return NSS_STATUS_UNAVAIL;
416 f = open_fopen_r(ctxt->mapname);
419 @@ -618,8 +604,8 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
420 struct lookup_context *ctxt = (struct lookup_context *) context;
421 struct map_source *source;
422 struct mapent_cache *mc;
425 + char key[KEY_MAX_LEN + 1];
426 + char mapent[MAPENT_MAX_LEN + 1];
428 unsigned int k_len, m_len;
430 @@ -639,20 +625,6 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
431 return NSS_STATUS_UNAVAIL;
434 - key = alloca(KEY_MAX_LEN + 1);
437 - MODPREFIX "could not malloc storage for key");
438 - return NSS_STATUS_UNAVAIL;
441 - mapent = alloca(MAPENT_MAX_LEN + 1);
444 - MODPREFIX "could not malloc storage for mapent");
445 - return NSS_STATUS_UNAVAIL;
448 f = open_fopen_r(ctxt->mapname);
451 @@ -972,7 +944,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
452 char key[KEY_MAX_LEN + 1];
456 + char mapent_buf[MAPENT_MAX_LEN + 1];
460 @@ -1076,38 +1048,36 @@ do_cache_lookup:
462 if (me && (me->source == source || *me->key == '/')) {
463 pthread_cleanup_push(cache_lock_cleanup, mc);
464 - mapent_len = strlen(me->mapent);
465 - mapent = alloca(mapent_len + 1);
466 - strcpy(mapent, me->mapent);
467 + strcpy(mapent_buf, me->mapent);
468 + mapent = mapent_buf;
469 pthread_cleanup_pop(0);
474 - master_source_current_wait(ap->entry);
475 - ap->entry->current = source;
477 + return NSS_STATUS_TRYAGAIN;
479 - debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
480 - ret = ctxt->parse->parse_mount(ap, key, key_len,
481 - mapent, ctxt->parse->context);
483 - time_t now = time(NULL);
485 + master_source_current_wait(ap->entry);
486 + ap->entry->current = source;
488 - cache_writelock(mc);
489 + debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
490 + ret = ctxt->parse->parse_mount(ap, key, key_len,
491 + mapent, ctxt->parse->context);
493 + time_t now = time(NULL);
496 + cache_writelock(mc);
497 + me = cache_lookup_distinct(mc, key);
499 + rv = cache_update(mc, source, key, NULL, now);
500 + if (rv != CHE_FAIL) {
501 me = cache_lookup_distinct(mc, key);
503 - rv = cache_update(mc, source, key, NULL, now);
504 - if (rv != CHE_FAIL) {
505 - me = cache_lookup_distinct(mc, key);
506 - me->status = now + ap->negative_timeout;
509 + me->status = now + ap->negative_timeout;
515 return NSS_STATUS_TRYAGAIN;
518 return NSS_STATUS_SUCCESS;
520 diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
521 index d8a60d3..094cbdc 100644
522 --- a/modules/lookup_ldap.c
523 +++ b/modules/lookup_ldap.c
524 @@ -294,10 +294,10 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
526 l += strlen(key) + strlen(ctxt->mapname) + strlen("(&(=))");
531 char *estr = strerror_r(errno, buf, sizeof(buf));
532 - crit(logopt, MODPREFIX "alloca: %s", estr);
533 + crit(logopt, MODPREFIX "malloc: %s", estr);
534 return NSS_STATUS_UNAVAIL;
537 @@ -310,6 +310,7 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
538 key, (int) strlen(ctxt->mapname), ctxt->mapname) >= l) {
540 MODPREFIX "error forming query string");
544 scope = LDAP_SCOPE_SUBTREE;
545 @@ -317,6 +318,7 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
546 if (sprintf(query, "(objectclass=%s)", class) >= l) {
548 MODPREFIX "error forming query string");
552 scope = LDAP_SCOPE_SUBTREE;
553 @@ -340,6 +342,7 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
555 MODPREFIX "query failed for %s: %s",
556 query, ldap_err2string(rv));
561 @@ -353,6 +356,7 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
562 MODPREFIX "query succeeded, no matches for %s",
564 ldap_msgfree(result);
569 @@ -395,10 +399,12 @@ static int get_query_dn(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt
570 ldap_msgfree(result);
572 MODPREFIX "failed to find query dn under search base dns");
581 ldap_msgfree(result);
582 @@ -1181,7 +1187,7 @@ static int parse_server_string(unsigned logopt, const char *url, struct lookup_c
585 estr = strerror_r(errno, buf, sizeof(buf));
586 - logerr(MODPREFIX "malloc: %s", estr);
587 + logerr(MODPREFIX "strdup: %s", estr);
591 @@ -1441,23 +1447,26 @@ int lookup_read_master(struct master *master, time_t age, void *context)
593 l = strlen("(objectclass=)") + strlen(class) + 1;
598 char *estr = strerror_r(errno, buf, sizeof(buf));
599 - logerr(MODPREFIX "alloca: %s", estr);
600 + logerr(MODPREFIX "malloc: %s", estr);
601 return NSS_STATUS_UNAVAIL;
604 if (sprintf(query, "(objectclass=%s)", class) >= l) {
605 error(logopt, MODPREFIX "error forming query string");
607 return NSS_STATUS_UNAVAIL;
611 /* Initialize the LDAP context. */
612 ldap = do_reconnect(logopt, ctxt);
616 return NSS_STATUS_UNAVAIL;
621 @@ -1469,6 +1478,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
622 error(logopt, MODPREFIX "query failed for %s: %s",
623 query, ldap_err2string(rv));
624 unbind_ldap_connection(logging, ldap, ctxt);
626 return NSS_STATUS_NOTFOUND;
629 @@ -1479,6 +1489,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
631 ldap_msgfree(result);
632 unbind_ldap_connection(logging, ldap, ctxt);
634 return NSS_STATUS_NOTFOUND;
636 debug(logopt, MODPREFIX "examining entries");
637 @@ -1548,6 +1559,7 @@ next:
639 ldap_msgfree(result);
640 unbind_ldap_connection(logopt, ldap, ctxt);
643 return NSS_STATUS_SUCCESS;
645 @@ -2174,7 +2186,7 @@ static int read_one_map(struct autofs_point *ap,
646 /* Build a query string. */
647 l = strlen("(objectclass=)") + strlen(class) + 1;
649 - sp.query = alloca(l);
650 + sp.query = malloc(l);
651 if (sp.query == NULL) {
652 char *estr = strerror_r(errno, buf, sizeof(buf));
653 logerr(MODPREFIX "malloc: %s", estr);
654 @@ -2183,14 +2195,17 @@ static int read_one_map(struct autofs_point *ap,
656 if (sprintf(sp.query, "(objectclass=%s)", class) >= l) {
657 error(ap->logopt, MODPREFIX "error forming query string");
659 return NSS_STATUS_UNAVAIL;
663 /* Initialize the LDAP context. */
664 sp.ldap = do_reconnect(ap->logopt, ctxt);
668 return NSS_STATUS_UNAVAIL;
673 @@ -2215,6 +2230,7 @@ static int read_one_map(struct autofs_point *ap,
674 if (rv != LDAP_SUCCESS || !sp.result) {
675 unbind_ldap_connection(ap->logopt, sp.ldap, ctxt);
678 return NSS_STATUS_UNAVAIL;
681 @@ -2223,6 +2239,7 @@ static int read_one_map(struct autofs_point *ap,
682 ldap_msgfree(sp.result);
683 unbind_ldap_connection(ap->logopt, sp.ldap, ctxt);
686 return NSS_STATUS_NOTFOUND;
688 ldap_msgfree(sp.result);
689 @@ -2233,6 +2250,7 @@ static int read_one_map(struct autofs_point *ap,
690 unbind_ldap_connection(ap->logopt, sp.ldap, ctxt);
695 return NSS_STATUS_SUCCESS;
697 @@ -2328,7 +2346,7 @@ static int lookup_one(struct autofs_point *ap,
699 l += 2*strlen(entry) + enc_len1 + enc_len2 + 6;
704 char *estr = strerror_r(errno, buf, sizeof(buf));
705 crit(ap->logopt, MODPREFIX "malloc: %s", estr);
706 @@ -2336,6 +2354,7 @@ static int lookup_one(struct autofs_point *ap,
714 @@ -2367,14 +2386,17 @@ static int lookup_one(struct autofs_point *ap,
717 MODPREFIX "error forming query string");
723 /* Initialize the LDAP context. */
724 ldap = do_reconnect(ap->logopt, ctxt);
732 MODPREFIX "searching for \"%s\" under \"%s\"", query, ctxt->qdn);
733 @@ -2384,6 +2406,7 @@ static int lookup_one(struct autofs_point *ap,
734 if ((rv != LDAP_SUCCESS) || !result) {
735 crit(ap->logopt, MODPREFIX "query failed for %s", query);
736 unbind_ldap_connection(ap->logopt, ldap, ctxt);
741 @@ -2396,6 +2419,7 @@ static int lookup_one(struct autofs_point *ap,
742 MODPREFIX "got answer, but no entry for %s", query);
743 ldap_msgfree(result);
744 unbind_ldap_connection(ap->logopt, ldap, ctxt);
749 @@ -2610,6 +2634,7 @@ next:
752 pthread_cleanup_pop(1);
757 @@ -2696,7 +2721,7 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
758 char key[KEY_MAX_LEN + 1];
762 + char mapent_buf[MAPENT_MAX_LEN + 1];
766 @@ -2766,38 +2791,36 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
767 me = cache_lookup_distinct(mc, "*");
769 if (me && (me->source == source || *me->key == '/')) {
770 - mapent_len = strlen(me->mapent);
771 - mapent = alloca(mapent_len + 1);
772 - strcpy(mapent, me->mapent);
773 + strcpy(mapent_buf, me->mapent);
774 + mapent = mapent_buf;
779 - master_source_current_wait(ap->entry);
780 - ap->entry->current = source;
782 + return NSS_STATUS_TRYAGAIN;
784 - debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
785 - ret = ctxt->parse->parse_mount(ap, key, key_len,
786 - mapent, ctxt->parse->context);
788 - time_t now = time(NULL);
790 + master_source_current_wait(ap->entry);
791 + ap->entry->current = source;
793 - /* Record the the mount fail in the cache */
794 - cache_writelock(mc);
795 + debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
796 + ret = ctxt->parse->parse_mount(ap, key, key_len,
797 + mapent, ctxt->parse->context);
799 + time_t now = time(NULL);
802 + /* Record the the mount fail in the cache */
803 + cache_writelock(mc);
804 + me = cache_lookup_distinct(mc, key);
806 + rv = cache_update(mc, source, key, NULL, now);
807 + if (rv != CHE_FAIL) {
808 me = cache_lookup_distinct(mc, key);
810 - rv = cache_update(mc, source, key, NULL, now);
811 - if (rv != CHE_FAIL) {
812 - me = cache_lookup_distinct(mc, key);
813 - me->status = now + ap->negative_timeout;
816 + me->status = now + ap->negative_timeout;
822 return NSS_STATUS_TRYAGAIN;
825 return NSS_STATUS_SUCCESS;
827 diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c
828 index 4c3ce60..0c75905 100644
829 --- a/modules/lookup_nisplus.c
830 +++ b/modules/lookup_nisplus.c
831 @@ -92,10 +92,10 @@ int lookup_read_master(struct master *master, time_t age, void *context)
834 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
835 - tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
836 + tablename = malloc(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
838 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
839 - logerr(MODPREFIX "alloca: %s", estr);
840 + logerr(MODPREFIX "malloc: %s", estr);
841 pthread_setcancelstate(cur_state, NULL);
842 return NSS_STATUS_UNAVAIL;
844 @@ -107,6 +107,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
845 nis_freeresult(result);
847 MODPREFIX "couldn't locate nis+ table %s", ctxt->mapname);
849 pthread_setcancelstate(cur_state, NULL);
850 return NSS_STATUS_NOTFOUND;
852 @@ -118,6 +119,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
853 nis_freeresult(result);
855 MODPREFIX "couldn't enumrate nis+ map %s", ctxt->mapname);
857 pthread_setcancelstate(cur_state, NULL);
858 return NSS_STATUS_UNAVAIL;
860 @@ -155,6 +157,7 @@ int lookup_read_master(struct master *master, time_t age, void *context)
863 nis_freeresult(result);
865 pthread_setcancelstate(cur_state, NULL);
867 return NSS_STATUS_SUCCESS;
868 @@ -180,10 +183,10 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
871 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
872 - tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
873 + tablename = malloc(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
875 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
876 - logerr(MODPREFIX "alloca: %s", estr);
877 + logerr(MODPREFIX "malloc: %s", estr);
878 pthread_setcancelstate(cur_state, NULL);
879 return NSS_STATUS_UNAVAIL;
881 @@ -195,6 +198,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
882 nis_freeresult(result);
884 MODPREFIX "couldn't locate nis+ table %s", ctxt->mapname);
886 pthread_setcancelstate(cur_state, NULL);
887 return NSS_STATUS_NOTFOUND;
889 @@ -206,6 +210,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
890 nis_freeresult(result);
892 MODPREFIX "couldn't enumrate nis+ map %s", ctxt->mapname);
894 pthread_setcancelstate(cur_state, NULL);
895 return NSS_STATUS_UNAVAIL;
897 @@ -245,6 +250,7 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
902 pthread_setcancelstate(cur_state, NULL);
904 return NSS_STATUS_SUCCESS;
905 @@ -271,11 +277,11 @@ static int lookup_one(struct autofs_point *ap,
908 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
909 - tablename = alloca(strlen(key) +
910 - strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
911 + tablename = malloc(strlen(key) + strlen(ctxt->mapname) +
912 + strlen(ctxt->domainname) + 20);
914 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
915 - logerr(MODPREFIX "alloca: %s", estr);
916 + logerr(MODPREFIX "malloc: %s", estr);
917 pthread_setcancelstate(cur_state, NULL);
920 @@ -286,6 +292,7 @@ static int lookup_one(struct autofs_point *ap,
921 if (result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) {
922 nis_error rs = result->status;
923 nis_freeresult(result);
925 pthread_setcancelstate(cur_state, NULL);
926 if (rs == NIS_NOTFOUND ||
927 rs == NIS_S_NOTFOUND ||
928 @@ -303,6 +310,7 @@ static int lookup_one(struct autofs_point *ap,
931 nis_freeresult(result);
933 pthread_setcancelstate(cur_state, NULL);
936 @@ -327,10 +335,10 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
939 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
940 - tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
941 + tablename = malloc(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20);
943 char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
944 - logerr(MODPREFIX "alloca: %s", estr);
945 + logerr(MODPREFIX "malloc: %s", estr);
946 pthread_setcancelstate(cur_state, NULL);
949 @@ -341,6 +349,7 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
950 if (result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) {
951 nis_error rs = result->status;
952 nis_freeresult(result);
954 pthread_setcancelstate(cur_state, NULL);
955 if (rs == NIS_NOTFOUND ||
956 rs == NIS_S_NOTFOUND ||
957 @@ -357,6 +366,7 @@ static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
960 nis_freeresult(result);
962 pthread_setcancelstate(cur_state, NULL);
965 @@ -546,36 +556,37 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
967 if (me && (me->source == source || *me->key == '/')) {
968 mapent_len = strlen(me->mapent);
969 - mapent = alloca(mapent_len + 1);
970 + mapent = malloc(mapent_len + 1);
971 strcpy(mapent, me->mapent);
976 - master_source_current_wait(ap->entry);
977 - ap->entry->current = source;
979 + return NSS_STATUS_TRYAGAIN;
981 - debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
982 - ret = ctxt->parse->parse_mount(ap, key, key_len,
983 - mapent, ctxt->parse->context);
985 - time_t now = time(NULL);
987 + master_source_current_wait(ap->entry);
988 + ap->entry->current = source;
990 + debug(ap->logopt, MODPREFIX "%s -> %s", key, mapent);
991 + ret = ctxt->parse->parse_mount(ap, key, key_len,
992 + mapent, ctxt->parse->context);
994 + time_t now = time(NULL);
997 - cache_writelock(mc);
998 + cache_writelock(mc);
999 + me = cache_lookup_distinct(mc, key);
1001 + rv = cache_update(mc, source, key, NULL, now);
1002 + if (rv != CHE_FAIL) {
1003 me = cache_lookup_distinct(mc, key);
1005 - rv = cache_update(mc, source, key, NULL, now);
1006 - if (rv != CHE_FAIL) {
1007 - me = cache_lookup_distinct(mc, key);
1008 - me->status = time(NULL) + ap->negative_timeout;
1011 + me->status = time(NULL) + ap->negative_timeout;
1018 return NSS_STATUS_TRYAGAIN;
1022 return NSS_STATUS_SUCCESS;
1024 diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c
1025 index 44fc043..fab2906 100644
1026 --- a/modules/mount_autofs.c
1027 +++ b/modules/mount_autofs.c
1032 -#include <alloca.h>
1033 #include <sys/param.h>
1034 #include <sys/types.h>
1035 #include <sys/stat.h>
1036 diff --git a/modules/mount_bind.c b/modules/mount_bind.c
1037 index 361f0c2..b8ef581 100644
1038 --- a/modules/mount_bind.c
1039 +++ b/modules/mount_bind.c
1040 @@ -69,7 +69,7 @@ out:
1041 int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
1042 const char *what, const char *fstype, const char *options, void *context)
1045 + char fullpath[PATH_MAX];
1046 char buf[MAX_ERR_BUF];
1049 @@ -80,14 +80,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1050 /* Root offset of multi-mount */
1052 if (root[len - 1] == '/') {
1053 - fullpath = alloca(len);
1054 len = snprintf(fullpath, len, "%s", root);
1055 /* Direct mount name is absolute path so don't use root */
1056 } else if (*name == '/') {
1057 - fullpath = alloca(len + 1);
1058 len = sprintf(fullpath, "%s", root);
1060 - fullpath = alloca(len + name_len + 2);
1061 len = sprintf(fullpath, "%s/%s", root, name);
1063 fullpath[len] = '\0';
1064 @@ -141,7 +138,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1068 - char *basepath = alloca(strlen(fullpath) + 1);
1069 + char basepath[PATH_MAX];
1073 diff --git a/modules/mount_changer.c b/modules/mount_changer.c
1074 index c30190d..856cf6a 100644
1075 --- a/modules/mount_changer.c
1076 +++ b/modules/mount_changer.c
1077 @@ -44,7 +44,7 @@ int mount_init(void **context)
1078 int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
1079 const char *what, const char *fstype, const char *options, void *context)
1082 + char fullpath[PATH_MAX];
1083 char buf[MAX_ERR_BUF];
1085 int len, status, existed = 1;
1086 @@ -57,14 +57,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1087 /* Root offset of multi-mount */
1089 if (root[len - 1] == '/') {
1090 - fullpath = alloca(len);
1091 len = snprintf(fullpath, len, "%s", root);
1092 /* Direct mount name is absolute path so don't use root */
1093 } else if (*name == '/') {
1094 - fullpath = alloca(len + 1);
1095 len = sprintf(fullpath, "%s", root);
1097 - fullpath = alloca(len + name_len + 2);
1098 len = sprintf(fullpath, "%s/%s", root, name);
1100 fullpath[len] = '\0';
1101 diff --git a/modules/mount_ext2.c b/modules/mount_ext2.c
1102 index 192ec04..85329ab 100644
1103 --- a/modules/mount_ext2.c
1104 +++ b/modules/mount_ext2.c
1105 @@ -36,7 +36,7 @@ int mount_init(void **context)
1106 int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
1107 const char *what, const char *fstype, const char *options, void *context)
1110 + char fullpath[PATH_MAX];
1111 char buf[MAX_ERR_BUF];
1114 @@ -49,14 +49,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1115 /* Root offset of multi-mount */
1117 if (root[len - 1] == '/') {
1118 - fullpath = alloca(len);
1119 len = snprintf(fullpath, len, "%s", root);
1120 /* Direct mount name is absolute path so don't use root */
1121 } else if (*name == '/') {
1122 - fullpath = alloca(len + 1);
1123 len = sprintf(fullpath, "%s", root);
1125 - fullpath = alloca(len + name_len + 2);
1126 len = sprintf(fullpath, "%s/%s", root, name);
1128 fullpath[len] = '\0';
1129 diff --git a/modules/mount_generic.c b/modules/mount_generic.c
1130 index 6d7b4b3..1dc1bfd 100644
1131 --- a/modules/mount_generic.c
1132 +++ b/modules/mount_generic.c
1133 @@ -37,7 +37,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1134 const char *what, const char *fstype, const char *options,
1138 + char fullpath[PATH_MAX];
1139 char buf[MAX_ERR_BUF];
1141 int len, status, existed = 1;
1142 @@ -48,14 +48,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int
1143 /* Root offset of multi-mount */
1145 if (root[len - 1] == '/') {
1146 - fullpath = alloca(len);
1147 len = snprintf(fullpath, len, "%s", root);
1148 /* Direct mount name is absolute path so don't use root */
1149 } else if (*name == '/') {
1150 - fullpath = alloca(len + 1);
1151 len = sprintf(fullpath, "%s", root);
1153 - fullpath = alloca(len + name_len + 2);
1154 len = sprintf(fullpath, "%s/%s", root, name);
1156 fullpath[len] = '\0';