Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ftpd - Always close(pdata) if it was a valid filedes...
details: https://anonhg.NetBSD.org/src/rev/50014bb7f699
branches: trunk
changeset: 486390:50014bb7f699
user: lukem <lukem%NetBSD.org@localhost>
date: Sat May 20 23:34:55 2000 +0000
description:
- Always close(pdata) if it was a valid filedescriptor before setting it to -1.
Problem noted in [bin/9642] by Takahiro Kambe <taca%sky.yamashina.kyoto.jp@localhost>,
(part of which already had been solved by itojun a while ago), and provided
patch covered most of the fixes needed. (Thanks Takahiro!)
- Consistently indent goto labels by one space.
diffstat:
libexec/ftpd/ftpd.c | 57 +++++++++++++++++++++++++++----------------------
libexec/ftpd/popen.c | 7 +++--
libexec/ftpd/version.h | 4 +-
3 files changed, 37 insertions(+), 31 deletions(-)
diffs (254 lines):
diff -r c4d7a5a95c2e -r 50014bb7f699 libexec/ftpd/ftpd.c
--- a/libexec/ftpd/ftpd.c Sat May 20 21:34:48 2000 +0000
+++ b/libexec/ftpd/ftpd.c Sat May 20 23:34:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpd.c,v 1.88 2000/05/20 02:20:18 lukem Exp $ */
+/* $NetBSD: ftpd.c,v 1.89 2000/05/20 23:34:55 lukem Exp $ */
/*
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -109,7 +109,7 @@
#if 0
static char sccsid[] = "@(#)ftpd.c 8.5 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: ftpd.c,v 1.88 2000/05/20 02:20:18 lukem Exp $");
+__RCSID("$NetBSD: ftpd.c,v 1.89 2000/05/20 23:34:55 lukem Exp $");
#endif
#endif /* not lint */
@@ -781,7 +781,7 @@
}
rval = 1;
-skip:
+ skip:
if (pw != NULL && pw->pw_expire && time(NULL) >= pw->pw_expire)
rval = 2;
/*
@@ -1071,8 +1071,7 @@
timersub(&finish, &start, &td);
tdp = &td;
data = -1;
- pdata = -1;
-done:
+ done:
if (log)
logcmd("get", byte_count, name, NULL, tdp, NULL);
closerv = (*closefunc)(fin);
@@ -1108,6 +1107,9 @@
reply(226, "Transfer complete.");
}
cleanupretrieve:
+ if (pdata >= 0)
+ (void)close(pdata);
+ pdata = -1;
if (stderrfd != -1)
(void)close(stderrfd);
if (isconversion)
@@ -1127,7 +1129,7 @@
if (unique && stat(name, &st) == 0 &&
(name = gunique(name)) == NULL) {
logcmd(desc, -1, name, NULL, NULL, "cannot create unique file");
- return;
+ goto cleanupstore;
}
if (restart_point)
@@ -1138,7 +1140,7 @@
if (fout == NULL) {
perror_reply(553, name);
logcmd(desc, -1, name, NULL, NULL, strerror(errno));
- return;
+ goto cleanupstore;
}
byte_count = -1;
if (restart_point) {
@@ -1184,10 +1186,13 @@
timersub(&finish, &start, &td);
tdp = &td;
data = -1;
- pdata = -1;
-done:
+ done:
logcmd(desc, byte_count, name, NULL, tdp, NULL);
(*closefunc)(fout);
+ cleanupstore:
+ if (pdata >= 0)
+ (void)close(pdata);
+ pdata = -1;
}
static FILE *
@@ -1228,7 +1233,7 @@
}
#endif
return (fdopen(s, mode));
-bad:
+ bad:
/* Return the real value of errno (close may change it) */
t = errno;
(void) seteuid((uid_t)pw->pw_uid);
@@ -1451,17 +1456,17 @@
goto cleanup_send_data;
}
-data_err:
+ data_err:
(void) alarm(0);
perror_reply(426, "Data connection");
goto cleanup_send_data;
-file_err:
+ file_err:
(void) alarm(0);
perror_reply(551, "Error on input file");
/* FALLTHROUGH */
-cleanup_send_data:
+ cleanup_send_data:
(void) alarm(0);
transflag = 0;
if (buf)
@@ -1605,17 +1610,17 @@
goto cleanup_recv_data;
}
-data_err:
+ data_err:
(void) alarm(0);
perror_reply(426, "Data Connection");
goto cleanup_recv_data;
-file_err:
+ file_err:
(void) alarm(0);
perror_reply(452, "Error writing file");
goto cleanup_recv_data;
-cleanup_recv_data:
+ cleanup_recv_data:
(void) alarm(0);
transflag = 0;
total_files_in++;
@@ -1666,7 +1671,7 @@
union sockunion *su = NULL;
static char ntop_buf[INET6_ADDRSTRLEN];
u_char *a, *p;
- int ispassive;
+ int ispassive, af;
off_t b, otbi, otbo, otb;
a = p = (u_char *)NULL;
@@ -1735,7 +1740,7 @@
total_bytes += b;
total_bytes_out += b;
su = (union sockunion *)&data_dest;
-printaddr:
+ printaddr:
/* PASV/PORT */
if (su->su_family == AF_INET) {
if (ispassive)
@@ -1790,10 +1795,7 @@
}
/* EPRT/EPSV */
-epsvonly:;
- {
- int af;
-
+ epsvonly:
switch (su->su_family) {
case AF_INET:
af = 1;
@@ -1819,7 +1821,6 @@
total_bytes_out += b;
}
}
- }
} else
lreply(0, "No data connection");
@@ -2218,7 +2219,7 @@
UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1]));
return;
-pasv_error:
+ pasv_error:
(void) close(pdata);
pdata = -1;
perror_reply(425, "Can't open passive connection");
@@ -2319,7 +2320,7 @@
/* more proper error code? */
}
- pasv_error:
+ pasv_error:
(void) close(pdata);
pdata = -1;
perror_reply(425, "Can't open passive connection");
@@ -2447,6 +2448,8 @@
(void) fclose(dout);
transflag = 0;
data = -1;
+ if (pdata >= 0)
+ (void)close(pdata);
pdata = -1;
}
goto out;
@@ -2525,9 +2528,11 @@
transflag = 0;
if (dout != NULL)
(void) fclose(dout);
+ else if (pdata >= 0)
+ (void)close(pdata);
data = -1;
pdata = -1;
-out:
+ out:
total_xfers++;
total_xfers_out++;
if (p)
diff -r c4d7a5a95c2e -r 50014bb7f699 libexec/ftpd/popen.c
--- a/libexec/ftpd/popen.c Sat May 20 21:34:48 2000 +0000
+++ b/libexec/ftpd/popen.c Sat May 20 23:34:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: popen.c,v 1.21 2000/05/20 02:20:19 lukem Exp $ */
+/* $NetBSD: popen.c,v 1.22 2000/05/20 23:34:55 lukem Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
#if 0
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
#else
-__RCSID("$NetBSD: popen.c,v 1.21 2000/05/20 02:20:19 lukem Exp $");
+__RCSID("$NetBSD: popen.c,v 1.22 2000/05/20 23:34:55 lukem Exp $");
#endif
#endif /* not lint */
@@ -208,7 +208,8 @@
}
pids[fileno(iop)] = pid;
-pfree: if (sl)
+ pfree:
+ if (sl)
sl_free(sl, 1);
return (iop);
}
diff -r c4d7a5a95c2e -r 50014bb7f699 libexec/ftpd/version.h
--- a/libexec/ftpd/version.h Sat May 20 21:34:48 2000 +0000
+++ b/libexec/ftpd/version.h Sat May 20 23:34:55 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.9 2000/05/20 02:20:20 lukem Exp $ */
+/* $NetBSD: version.h,v 1.10 2000/05/20 23:34:55 lukem Exp $ */
/*-
* Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -36,5 +36,5 @@
*/
#ifndef FTPD_VERSION
-#define FTPD_VERSION "NetBSD-ftpd 20000520"
+#define FTPD_VERSION "NetBSD-ftpd 20000521"
#endif
Home |
Main Index |
Thread Index |
Old Index