autofs-5.0.3 - fix bad alloca usage

From: Ian Kent <raven@themaw.net>

In the lookup_ghost() function alloca is used within a loop which can
lead to stack overflow.
---

 CHANGELOG       |    1 +
 daemon/lookup.c |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletions(-)


diff --git a/CHANGELOG b/CHANGELOG
index 879380e..07feb29 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -48,6 +48,7 @@
 - fix $mandir definition in Makefile.conf.in
 - fix init script stop function.
 - fix master map lexer eval order.
+- fix bad alloca usage.
  
 14/01/2008 autofs-5.0.3
 -----------------------
diff --git a/daemon/lookup.c b/daemon/lookup.c
index 2233ac8..49030e1 100644
--- a/daemon/lookup.c
+++ b/daemon/lookup.c
@@ -608,7 +608,7 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 				goto next;
 			}
 
-			fullpath = alloca(strlen(me->key) + strlen(root) + 3);
+			fullpath = malloc(strlen(me->key) + strlen(root) + 3);
 			if (!fullpath) {
 				warn(ap->logopt, "failed to allocate full path");
 				goto next;
@@ -619,6 +619,7 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 			if (ret == -1 && errno != ENOENT) {
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 				warn(ap->logopt, "stat error %s", estr);
+				free(fullpath);
 				goto next;
 			}
 
@@ -627,6 +628,7 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 				char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
 				warn(ap->logopt,
 				     "mkdir_path %s failed: %s", fullpath, estr);
+				free(fullpath);
 				goto next;
 			}
 
@@ -634,6 +636,8 @@ int lookup_ghost(struct autofs_point *ap, const char *root)
 				me->dev = st.st_dev;
 				me->ino = st.st_ino;
 			}
+
+			free(fullpath);
 next:
 			me = cache_enumerate(mc, me);
 		}
