forked from mirrors/tftp-hpa-google
Fix massive lossage: 0.15 based on an outdated repository!!!
This commit is contained in:
parent
0ba1a99f5d
commit
7a15e40374
8 changed files with 345 additions and 427 deletions
37
tftp/main.c
37
tftp/main.c
|
@ -43,10 +43,6 @@ static const char *copyright =
|
|||
static const char *rcsid = "tftp-hpa $Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#define MAXHOSTNAMELEN 256
|
||||
#endif
|
||||
|
||||
/* Many bug fixes are from Jim Guyton <guyton@rand-unix> */
|
||||
|
||||
/*
|
||||
|
@ -72,6 +68,14 @@ static const char *rcsid = "tftp-hpa $Id$";
|
|||
|
||||
#include "extern.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 /* secs between rexmt's */
|
||||
#define LBUFLEN 200 /* size of input buffer */
|
||||
|
||||
|
@ -86,7 +90,7 @@ char line[LBUFLEN];
|
|||
int margc;
|
||||
char *margv[20];
|
||||
char *prompt = "tftp";
|
||||
jmp_buf toplevel;
|
||||
sigjmp_buf toplevel;
|
||||
void intr(int);
|
||||
struct servent *sp;
|
||||
|
||||
|
@ -153,6 +157,8 @@ struct cmd cmdtab[] = {
|
|||
struct cmd *getcmd(char *);
|
||||
char *tail(char *);
|
||||
|
||||
char *xstrdup(const char *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -175,13 +181,13 @@ main(int argc, char *argv[])
|
|||
exit(1);
|
||||
}
|
||||
strcpy(mode, "netascii");
|
||||
signal(SIGINT, intr);
|
||||
bsd_signal(SIGINT, intr);
|
||||
if (argc > 1) {
|
||||
if (setjmp(toplevel) != 0)
|
||||
if (sigsetjmp(toplevel,1) != 0)
|
||||
exit(0);
|
||||
setpeer(argc, argv);
|
||||
}
|
||||
if (setjmp(toplevel) != 0)
|
||||
if (sigsetjmp(toplevel,1) != 0)
|
||||
(void)putchar('\n');
|
||||
|
||||
command();
|
||||
|
@ -189,7 +195,7 @@ main(int argc, char *argv[])
|
|||
return 0; /* Never reached */
|
||||
}
|
||||
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
char *hostname;
|
||||
|
||||
void
|
||||
setpeer(int argc, char *argv[])
|
||||
|
@ -210,8 +216,7 @@ setpeer(int argc, char *argv[])
|
|||
}
|
||||
if (inet_aton(argv[1], &peeraddr.sin_addr) != 0) {
|
||||
peeraddr.sin_family = AF_INET;
|
||||
(void) strncpy(hostname, argv[1], sizeof hostname);
|
||||
hostname[sizeof(hostname)-1] = '\0';
|
||||
hostname = xstrdup(argv[1]);
|
||||
} else {
|
||||
host = gethostbyname(argv[1]);
|
||||
if (host == 0) {
|
||||
|
@ -221,7 +226,7 @@ setpeer(int argc, char *argv[])
|
|||
}
|
||||
peeraddr.sin_family = host->h_addrtype;
|
||||
bcopy(host->h_addr, &peeraddr.sin_addr, host->h_length);
|
||||
(void) strcpy(hostname, host->h_name);
|
||||
hostname = xstrdup(host->h_name);
|
||||
}
|
||||
port = sp->s_port;
|
||||
if (argc == 3) {
|
||||
|
@ -349,7 +354,7 @@ put(int argc, char *argv[])
|
|||
bcopy(hp->h_addr, (caddr_t)&peeraddr.sin_addr, hp->h_length);
|
||||
peeraddr.sin_family = hp->h_addrtype;
|
||||
connected = 1;
|
||||
strcpy(hostname, hp->h_name);
|
||||
hostname = xstrdup(hp->h_name);
|
||||
}
|
||||
if (!connected) {
|
||||
printf("No target machine specified.\n");
|
||||
|
@ -443,7 +448,7 @@ get(int argc, char *argv[])
|
|||
hp->h_length);
|
||||
peeraddr.sin_family = hp->h_addrtype;
|
||||
connected = 1;
|
||||
strcpy(hostname, hp->h_name);
|
||||
hostname = xstrdup(hp->h_name);
|
||||
}
|
||||
if (argc < 4) {
|
||||
cp = argc == 3 ? argv[2] : tail(src);
|
||||
|
@ -549,9 +554,9 @@ void
|
|||
intr(int sig)
|
||||
{
|
||||
|
||||
signal(SIGALRM, SIG_IGN);
|
||||
bsd_signal(SIGALRM, SIG_IGN);
|
||||
alarm(0);
|
||||
longjmp(toplevel, -1);
|
||||
siglongjmp(toplevel, -1);
|
||||
}
|
||||
|
||||
char *
|
||||
|
|
24
tftp/tftp.c
24
tftp/tftp.c
|
@ -65,7 +65,13 @@ static const char *rcsid = "tftp-hpa $Id$";
|
|||
#include "extern.h"
|
||||
#include "tftpsubs.h"
|
||||
|
||||
extern int errno;
|
||||
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
|
||||
|
||||
extern struct sockaddr_in peeraddr; /* filled in by main */
|
||||
extern int f; /* the opened socket */
|
||||
|
@ -84,8 +90,8 @@ extern int maxtimeout;
|
|||
#define PKTSIZE SEGSIZE+4
|
||||
char ackbuf[PKTSIZE];
|
||||
int timeout;
|
||||
jmp_buf toplevel;
|
||||
jmp_buf timeoutbuf;
|
||||
sigjmp_buf toplevel;
|
||||
sigjmp_buf timeoutbuf;
|
||||
|
||||
static void nak(int);
|
||||
static int makerequest(int, const char *, struct tftphdr *, const char *);
|
||||
|
@ -118,7 +124,7 @@ sendfile(int fd, char *name, char *mode)
|
|||
block = 0;
|
||||
amount = 0;
|
||||
|
||||
signal(SIGALRM, timer);
|
||||
bsd_signal(SIGALRM, timer);
|
||||
do {
|
||||
if (block == 0)
|
||||
size = makerequest(WRQ, name, dp, mode) - 4;
|
||||
|
@ -133,7 +139,7 @@ sendfile(int fd, char *name, char *mode)
|
|||
dp->th_block = htons((u_short)block);
|
||||
}
|
||||
timeout = 0;
|
||||
(void) setjmp(timeoutbuf);
|
||||
(void) sigsetjmp(timeoutbuf,1);
|
||||
send_data:
|
||||
if (trace)
|
||||
tpacket("sent", dp, size + 4);
|
||||
|
@ -222,7 +228,7 @@ recvfile(int fd, char *name, char *mode)
|
|||
firsttrip = 1;
|
||||
amount = 0;
|
||||
|
||||
signal(SIGALRM, timer);
|
||||
bsd_signal(SIGALRM, timer);
|
||||
do {
|
||||
if (firsttrip) {
|
||||
size = makerequest(RRQ, name, ap, mode);
|
||||
|
@ -234,7 +240,7 @@ recvfile(int fd, char *name, char *mode)
|
|||
block++;
|
||||
}
|
||||
timeout = 0;
|
||||
(void) setjmp(timeoutbuf);
|
||||
(void) sigsetjmp(timeoutbuf,1);
|
||||
send_ack:
|
||||
if (trace)
|
||||
tpacket("sent", ap, size);
|
||||
|
@ -446,8 +452,8 @@ timer(int sig)
|
|||
if (timeout >= maxtimeout) {
|
||||
printf("Transfer timed out.\n");
|
||||
errno = save_errno;
|
||||
longjmp(toplevel, -1);
|
||||
siglongjmp(toplevel, -1);
|
||||
}
|
||||
errno = save_errno;
|
||||
longjmp(timeoutbuf, 1);
|
||||
siglongjmp(timeoutbuf, 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue