diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-27 12:37:00 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-06-27 12:37:00 +0200 |
commit | 27c290f7f29fc57385d53893bfd7301db4708e9c (patch) | |
tree | 4ca6e2c6ed7b1a3e1d574015faca0350b94b094b | |
parent | a6ae999b3b30ad522272325bac4c69b153150108 (diff) | |
download | busybox-w32-27c290f7f29fc57385d53893bfd7301db4708e9c.tar.gz busybox-w32-27c290f7f29fc57385d53893bfd7301db4708e9c.tar.bz2 busybox-w32-27c290f7f29fc57385d53893bfd7301db4708e9c.zip |
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>
-rw-r--r-- | networking/ftpd.c | 8 |
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) | |||
620 | const char *argv[5]; | 620 | const char *argv[5]; |
621 | struct fd_pair outfd; | 621 | struct fd_pair outfd; |
622 | pid_t pid; | 622 | pid_t pid; |
623 | #if !BB_MMU | 623 | |
624 | int cur_fd = xopen(".", O_RDONLY | O_DIRECTORY); | ||
625 | #endif | ||
626 | argv[0] = "ftpd"; | 624 | argv[0] = "ftpd"; |
627 | argv[1] = opt; /* "-l" or "-1" */ | 625 | argv[1] = opt; /* "-l" or "-1" */ |
628 | argv[2] = "--"; | 626 | argv[2] = "--"; |
@@ -646,6 +644,9 @@ popen_ls(const char *opt) | |||
646 | /*fflush_all(); - so far we dont use stdio on output */ | 644 | /*fflush_all(); - so far we dont use stdio on output */ |
647 | pid = BB_MMU ? xfork() : xvfork(); | 645 | pid = BB_MMU ? xfork() : xvfork(); |
648 | if (pid == 0) { | 646 | if (pid == 0) { |
647 | #if !BB_MMU | ||
648 | int cur_fd; | ||
649 | #endif | ||
649 | /* child */ | 650 | /* child */ |
650 | /* NB: close _first_, then move fd! */ | 651 | /* NB: close _first_, then move fd! */ |
651 | close(outfd.rd); | 652 | close(outfd.rd); |
@@ -660,6 +661,7 @@ popen_ls(const char *opt) | |||
660 | /* memset(&G, 0, sizeof(G)); - ls_main does it */ | 661 | /* memset(&G, 0, sizeof(G)); - ls_main does it */ |
661 | exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv)); | 662 | exit(ls_main(ARRAY_SIZE(argv) - 1, (char**) argv)); |
662 | #else | 663 | #else |
664 | cur_fd = xopen(".", O_RDONLY | O_DIRECTORY); | ||
663 | /* On NOMMU, we want to execute a child - copy of ourself | 665 | /* On NOMMU, we want to execute a child - copy of ourself |
664 | * in order to unblock parent after vfork. | 666 | * in order to unblock parent after vfork. |
665 | * In chroot we usually can't re-exec. Thus we escape | 667 | * In chroot we usually can't re-exec. Thus we escape |