summaryrefslogtreecommitdiff
path: root/libexec/ftpd/ftpd.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-03-09 19:09:13 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-03-09 19:09:13 +0000
commita0554841b1c1c55134b140b06f989028709310e2 (patch)
treed4b350f937db0204680c775a52e3f590c58d9d0d /libexec/ftpd/ftpd.c
parent225ef5f7b49ba100dc7d9cc8ebbf3262ea29d3a6 (diff)
Block all signals in lostconn() and sigprocmask() since we are headed
for _exit(). Fixes a signal handler race condition.
Diffstat (limited to 'libexec/ftpd/ftpd.c')
-rw-r--r--libexec/ftpd/ftpd.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 8028966a1b2..3ff824e0dce 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftpd.c,v 1.93 2001/03/09 18:38:25 deraadt Exp $ */
+/* $OpenBSD: ftpd.c,v 1.94 2001/03/09 19:09:12 millert Exp $ */
/* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */
/*
@@ -148,6 +148,8 @@ union sockunion data_dest;
union sockunion his_addr;
union sockunion pasv_addr;
+sigset_t allsigs;
+
int daemon_mode = 0;
int data;
jmp_buf errcatch, urgcatch;
@@ -299,7 +301,8 @@ main(argc, argv, envp)
FILE *fp;
struct hostent *hp;
- tzset(); /* in case no timezone database in ~ftp */
+ tzset(); /* in case no timezone database in ~ftp */
+ sigfillset(&allsigs); /* used to block signals while root */
while ((ch = getopt(argc, argv, argstr)) != -1) {
switch (ch) {
@@ -625,7 +628,8 @@ static void
lostconn(signo)
int signo;
{
- /* XXX signal races */
+
+ sigprocmask(SIG_BLOCK, &allsigs, NULL);
if (debug)
syslog(LOG_DEBUG, "lost connection");
dologout(1);
@@ -635,7 +639,8 @@ static void
sigquit(signo)
int signo;
{
- /* XXX signal races */
+
+ sigprocmask(SIG_BLOCK, &allsigs, NULL);
syslog(LOG_ERR, "got signal %s", sys_signame[signo]);
dologout(1);
}
@@ -827,8 +832,7 @@ checkuser(fname, name)
static void
end_login()
{
- sigset_t allsigs;
- sigfillset (&allsigs);
+
sigprocmask (SIG_BLOCK, &allsigs, NULL);
(void) seteuid((uid_t)0);
if (logged_in) {
@@ -853,7 +857,6 @@ pass(passwd)
FILE *fp;
static char homedir[MAXPATHLEN];
char *dir, rootdir[MAXPATHLEN];
- sigset_t allsigs;
if (logged_in || askpasswd == 0) {
reply(503, "Login with USER first.");
@@ -1015,7 +1018,6 @@ skip:
reply(550, "Can't set uid.");
goto bad;
}
- sigfillset(&allsigs);
sigprocmask(SIG_UNBLOCK, &allsigs, NULL);
/*
@@ -1240,11 +1242,9 @@ getdatasock(mode)
char *mode;
{
int on = 1, s, t, tries;
- sigset_t allsigs;
if (data >= 0)
return (fdopen(data, mode));
- sigfillset(&allsigs);
sigprocmask (SIG_BLOCK, &allsigs, NULL);
(void) seteuid((uid_t)0);
s = socket(ctrl_addr.su_family, SOCK_STREAM, 0);
@@ -1265,7 +1265,6 @@ getdatasock(mode)
sleep(tries);
}
(void) seteuid((uid_t)pw->pw_uid);
- sigfillset(&allsigs);
sigprocmask (SIG_UNBLOCK, &allsigs, NULL);
#ifdef IP_TOS
@@ -1298,7 +1297,6 @@ bad:
/* Return the real value of errno (close may change it) */
t = errno;
(void) seteuid((uid_t)pw->pw_uid);
- sigfillset (&allsigs);
sigprocmask (SIG_UNBLOCK, &allsigs, NULL);
(void) close(s);
errno = t;
@@ -2079,12 +2077,10 @@ void
dologout(status)
int status;
{
- sigset_t allsigs;
transflag = 0;
if (logged_in) {
- sigfillset(&allsigs);
sigprocmask(SIG_BLOCK, &allsigs, NULL);
(void) seteuid((uid_t)0);
ftpdlogwtmp(ttyline, "", "");