summaryrefslogtreecommitdiff
path: root/libexec/ftpd/ftpd.c
diff options
context:
space:
mode:
authorMoritz Jodeit <moritz@cvs.openbsd.org>2004-12-03 23:57:41 +0000
committerMoritz Jodeit <moritz@cvs.openbsd.org>2004-12-03 23:57:41 +0000
commitfae7ab50e9f9173b6178f0f637a9cb327ec548bf (patch)
tree673db9f7a09a4b7a46b6bd6bb36143831621a957 /libexec/ftpd/ftpd.c
parentb4e6fa2090f102b7fc6838056c2df31358d83d4e (diff)
make reply() reentrant. fixes a signal race.
ok henning@
Diffstat (limited to 'libexec/ftpd/ftpd.c')
-rw-r--r--libexec/ftpd/ftpd.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 66b5ce7e170..82206351a02 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftpd.c,v 1.159 2004/11/28 22:29:44 henning Exp $ */
+/* $OpenBSD: ftpd.c,v 1.160 2004/12/03 23:57:40 moritz Exp $ */
/* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */
/*
@@ -70,7 +70,7 @@ static const char copyright[] =
static const char sccsid[] = "@(#)ftpd.c 8.4 (Berkeley) 4/16/94";
#else
static const char rcsid[] =
- "$OpenBSD: ftpd.c,v 1.159 2004/11/28 22:29:44 henning Exp $";
+ "$OpenBSD: ftpd.c,v 1.160 2004/12/03 23:57:40 moritz Exp $";
#endif
#endif /* not lint */
@@ -1907,27 +1907,27 @@ fatal(char *s)
void
reply(int n, const char *fmt, ...)
{
- char *buf, *p, *next;
- int rval;
+ char *p, *next;
+ char msg[BUFSIZ];
+ char buf[BUFSIZ];
va_list ap;
+ struct syslog_data sdata = SYSLOG_DATA_INIT;
va_start(ap, fmt);
- rval = vasprintf(&buf, fmt, ap);
+ vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
- if (rval == -1 || buf == NULL) {
- printf("412 Local resource failure: malloc\r\n");
- fflush(stdout);
- dologout(1);
- }
- next = buf;
+
+ next = msg;
+
while ((p = strsep(&next, "\n\r"))) {
- printf("%d%s %s\r\n", n, (next != '\0') ? "-" : "", p);
- if (debug)
- syslog(LOG_DEBUG, "<--- %d%s %s", n,
- (next != '\0') ? "-" : "", p);
+ snprintf(buf, sizeof(buf), "%d%s %s\r\n", n,
+ (next != '\0') ? "-" : "", p);
+ write(STDOUT_FILENO, buf, strlen(buf));
+ if (debug) {
+ buf[strlen(buf) - 2] = '\0';
+ syslog_r(LOG_DEBUG, &sdata, "<--- %s", buf);
+ }
}
- (void)fflush(stdout);
- free(buf);
}
void