summaryrefslogtreecommitdiffhomepage
path: root/networking/ftpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-06-27 12:37:00 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-06-27 12:37:00 +0200
commit27c290f7f29fc57385d53893bfd7301db4708e9c (patch)
tree4ca6e2c6ed7b1a3e1d574015faca0350b94b094b /networking/ftpd.c
parenta6ae999b3b30ad522272325bac4c69b153150108 (diff)
ftpd: for LIST, open current directory *in the child*
Last change introduced an open fd leak. This is the fix. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/ftpd.c')
-rw-r--r--networking/ftpd.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 839a85d73..e7cf5f431 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -620,9 +620,7 @@ popen_ls(const char *opt)
const char *argv[5];
struct fd_pair outfd;
pid_t pid;
-#if !BB_MMU
- int cur_fd = xopen(".", O_RDONLY | O_DIRECTORY);
-#endif
+
argv[0] = "ftpd";
argv[1] = opt; /* "-l" or "-1" */
argv[2] = "--";
@@ -646,6 +644,9 @@ popen_ls(const char *opt)
/*fflush_all(); - so far we dont use stdio on output */
pid = BB_MMU ? xfork() : xvfork();
if (pid == 0) {
+#if !BB_MMU
+ int cur_fd;
+#endif
/* child */
/* NB: close _first_, then move fd! */
close(outfd.rd);
@@ -660,6 +661,7 @@ popen_ls(const char *opt)
/* memset(&G, 0, sizeof(G)); - ls_main does it */
exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv));
#else
+ cur_fd = xopen(".", O_RDONLY | O_DIRECTORY);
/* On NOMMU, we want to execute a child - copy of ourself
* in order to unblock parent after vfork.
* In chroot we usually can't re-exec. Thus we escape