From 0ba1a99f5d2cafe313479d26e5e93554daa601a5 Mon Sep 17 00:00:00 2001 From: hpa Date: Fri, 30 Mar 2001 01:07:52 +0000 Subject: [PATCH] Fix major lossage: 0.15 got based on an outdated repository!!! --- tftpd/tftpd.8 | 4 ++-- tftpd/tftpd.c | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tftpd/tftpd.8 b/tftpd/tftpd.8 index 0df83bf..0d2c281 100644 --- a/tftpd/tftpd.8 +++ b/tftpd/tftpd.8 @@ -34,7 +34,7 @@ .\" from: @(#)tftpd.8 6.7 (Berkeley) 5/13/91 .\" $OpenBSD: tftpd.8,v 1.7 1999/07/09 13:35:51 aaron Exp $ .\" -.Dd June 11, 1997 +.Dd July 9, 2000 .Dt TFTPD 8 .Os .Sh NAME @@ -111,7 +111,7 @@ This version of supports RFC 2347 option negotiation; the current version supports the .Pa blksize (RFC 2348), -.Pa blksize , +.Pa tsize , (RFC 2349), and .Pa timeout (RFC 2349) options. The diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 0bc56a4..4e3efa3 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -75,6 +75,14 @@ static const char *rcsid = "tftp-hpa $Id$"; #include "tftpsubs.h" #include "recvfrom.h" +void bsd_signal(int, void (*)(int)); + +#ifndef HAVE_SIGSETJMP +#define sigsetjmp(x,y) setjmp(x) +#define siglongjmp(x,y) longjmp(x,y) +#define sigjmp_buf jmp_buf +#endif + #define TIMEOUT 5 /* Default timeout (seconds) */ #define TRIES 4 /* Number of attempts to send each packet */ #define TIMEOUT_LIMIT (TRIES*(TRIES+1)/2) @@ -86,8 +94,8 @@ static const char *rcsid = "tftp-hpa $Id$"; #define EOPTNEG 8 #endif -extern int errno; extern char *__progname; +struct sockaddr_in s_in; int peer; int timeout = TIMEOUT; int rexmtval = TIMEOUT; @@ -147,7 +155,6 @@ main(int argc, char **argv) struct tftphdr *tp; struct passwd *pw; struct options *opt; - struct sockaddr_in myaddr; int n = 0; int on = 1; int fd = 0; @@ -625,7 +632,7 @@ validate_access(char *filename, int mode, struct formats *pf) } int timeout; -jmp_buf timeoutbuf; +sigjmp_buf timeoutbuf; void timer(int sig) @@ -634,7 +641,7 @@ timer(int sig) timeout += rexmtval; if (timeout >= maxtimeout) exit(0); - longjmp(timeoutbuf, 1); + siglongjmp(timeoutbuf, 1); } /* @@ -647,18 +654,18 @@ sendfile(struct formats *pf, struct tftphdr *oap, int oacklen) struct tftphdr *ap; /* ack packet */ int block = 1, size, n; - signal(SIGALRM, timer); ap = (struct tftphdr *)ackbuf; if (oap) { timeout = 0; - (void)setjmp(timeoutbuf); + (void)sigsetjmp(timeoutbuf,1); oack: if (send(peer, oap, oacklen, 0) != oacklen) { syslog(LOG_ERR, "tftpd: oack: %m\n"); goto abort; } for ( ; ; ) { + bsd_signal(SIGALRM, timer); alarm(rexmtval); n = recv(peer, ackbuf, sizeof(ackbuf), 0); alarm(0); @@ -694,7 +701,7 @@ oack: dp->th_opcode = htons((u_short)DATA); dp->th_block = htons((u_short)block); timeout = 0; - (void) setjmp(timeoutbuf); + (void) sigsetjmp(timeoutbuf,1); send_data: if (send(peer, dp, size + 4, 0) != size + 4) { @@ -703,6 +710,7 @@ send_data: } read_ahead(file, pf->f_convert); for ( ; ; ) { + bsd_signal(SIGALRM, timer); alarm(rexmtval); /* read the ack */ n = recv(peer, ackbuf, sizeof (ackbuf), 0); alarm(0); @@ -751,12 +759,11 @@ recvfile(struct formats *pf, struct tftphdr *oap, int oacklen) struct tftphdr *ap; /* ack buffer */ int block = 0, acksize, n, size; - signal(SIGALRM, timer); dp = w_init(); do { timeout = 0; - if (!block++ && oap) { + if (!block && oap) { ap = (struct tftphdr *)ackbuf; acksize = oacklen; } else { @@ -765,7 +772,9 @@ recvfile(struct formats *pf, struct tftphdr *oap, int oacklen) ap->th_block = htons((u_short)block); acksize = 4; } - (void) setjmp(timeoutbuf); + block++; + (void) sigsetjmp(timeoutbuf,1); + bsd_signal(SIGALRM, timer); send_ack: if (send(peer, ackbuf, acksize, 0) != acksize) { syslog(LOG_ERR, "tftpd: write(ack): %m"); @@ -773,6 +782,7 @@ send_ack: } write_behind(file, pf->f_convert); for ( ; ; ) { + bsd_signal(SIGALRM, timer); alarm(rexmtval); n = recv(peer, dp, PKTSIZE, 0); alarm(0); @@ -809,7 +819,7 @@ send_ack: ap->th_block = htons((u_short)(block)); (void) send(peer, ackbuf, 4, 0); - signal(SIGALRM, justquit); /* just quit on timeout */ + bsd_signal(SIGALRM, justquit); /* just quit on timeout */ alarm(rexmtval); n = recv(peer, buf, sizeof (buf), 0); /* normally times out and quits */ alarm(0);