Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109842545
D38958.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D38958.diff
View Options
diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -84,7 +84,7 @@
static int connected;
static char mode[32];
static jmp_buf toplevel;
-volatile int txrx_error;
+static int txrx_error;
static int peer;
#define MAX_MARGV 20
@@ -501,7 +501,8 @@
if (verbose)
printf("putting %s to %s:%s [%s]\n",
cp, hostname, targ, mode);
- xmitfile(peer, port, fd, targ, mode);
+ if (xmitfile(peer, port, fd, targ, mode))
+ txrx_error = 1;
close(fd);
return;
}
@@ -529,7 +530,8 @@
if (verbose)
printf("putting %s to %s:%s [%s]\n",
argv[n], hostname, path, mode);
- xmitfile(peer, port, fd, path, mode);
+ if (xmitfile(peer, port, fd, path, mode) != 0)
+ txrx_error = 1;
close(fd);
free(path);
@@ -605,7 +607,8 @@
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- recvfile(peer, port, fd, src, mode);
+ if (recvfile(peer, port, fd, src, mode) != 0)
+ txrx_error = 1;
break;
}
cp = tail(src); /* new .. jdg */
@@ -617,7 +620,8 @@
if (verbose)
printf("getting from %s:%s to %s [%s]\n",
hostname, src, cp, mode);
- recvfile(peer, port, fd, src, mode);
+ if (recvfile(peer, port, fd, src, mode) != 0)
+ txrx_error = 1;
}
}
diff --git a/usr.bin/tftp/tftp.h b/usr.bin/tftp/tftp.h
--- a/usr.bin/tftp/tftp.h
+++ b/usr.bin/tftp/tftp.h
@@ -32,9 +32,8 @@
* $FreeBSD$
*/
-void recvfile(int peer, char *port, int fd, char *name, char *mode);
-void xmitfile(int peer, char *port, int fd, char *name, char *mode);
+int recvfile(int peer, char *port, int fd, char *name, char *mode);
+int xmitfile(int peer, char *port, int fd, char *name, char *mode);
extern int verbose;
extern int maxtimeout;
-extern volatile int txrx_error;
diff --git a/usr.bin/tftp/tftp.c b/usr.bin/tftp/tftp.c
--- a/usr.bin/tftp/tftp.c
+++ b/usr.bin/tftp/tftp.c
@@ -68,11 +68,11 @@
/*
* Send the requested file.
*/
-void
+int
xmitfile(int peer, char *port, int fd, char *name, char *mode)
{
struct tftphdr *rp;
- int n, i;
+ int n, i, ret = 0;
uint16_t block;
struct sockaddr_storage serv; /* valid server port number */
char recvbuffer[MAXPKTSIZE];
@@ -102,7 +102,7 @@
n = send_wrq(peer, name, mode);
if (n > 0) {
printf("Cannot send WRQ packet\n");
- return;
+ return -1;
}
/*
@@ -131,11 +131,11 @@
}
if (i == 12) {
printf("Transfer timed out.\n");
- return;
+ return -1;
}
if (rp->th_opcode == ERROR) {
printf("Got ERROR, aborted\n");
- return;
+ return -1;
}
/*
@@ -146,7 +146,7 @@
if (!options_rfc_enabled) {
printf("Got OACK while options are not enabled!\n");
send_error(peer, EBADOP);
- return;
+ return -1;
}
parse_options(peer, rp->th_stuff, n + 2);
@@ -154,29 +154,29 @@
if (read_init(fd, NULL, mode) < 0) {
warn("read_init()");
- return;
+ return -1;
}
block = 1;
- tftp_send(peer, &block, &tftp_stats);
+ if (tftp_send(peer, &block, &tftp_stats) != 0)
+ ret = -1;
read_close();
if (tftp_stats.amount > 0)
printstats("Sent", verbose, &tftp_stats);
-
- txrx_error = 1;
+ return ret;
}
/*
* Receive a file.
*/
-void
+int
recvfile(int peer, char *port, int fd, char *name, char *mode)
{
struct tftphdr *rp;
uint16_t block;
char recvbuffer[MAXPKTSIZE];
- int n, i;
+ int n, i, ret = 0;
struct tftp_stats tftp_stats;
stats_init(&tftp_stats);
@@ -202,7 +202,7 @@
n = send_rrq(peer, name, mode);
if (n > 0) {
printf("Cannot send RRQ packet\n");
- return;
+ return -1;
}
/*
@@ -231,16 +231,16 @@
}
if (i == 12) {
printf("Transfer timed out.\n");
- return;
+ return -1;
}
if (rp->th_opcode == ERROR) {
tftp_log(LOG_ERR, "Error code %d: %s", rp->th_code, rp->th_msg);
- return;
+ return -1;
}
if (write_init(fd, NULL, mode) < 0) {
warn("write_init");
- return;
+ return -1;
}
/*
@@ -251,7 +251,7 @@
if (!options_rfc_enabled) {
printf("Got OACK while options are not enabled!\n");
send_error(peer, EBADOP);
- return;
+ return -1;
}
parse_options(peer, rp->th_stuff, n + 2);
@@ -259,16 +259,18 @@
n = send_ack(peer, 0);
if (n > 0) {
printf("Cannot send ACK on OACK.\n");
- return;
+ return -1;
}
block = 0;
- tftp_receive(peer, &block, &tftp_stats, NULL, 0);
+ if (tftp_receive(peer, &block, &tftp_stats, NULL, 0) != 0)
+ ret = -1;
} else {
block = 1;
- tftp_receive(peer, &block, &tftp_stats, rp, n);
+ if (tftp_receive(peer, &block, &tftp_stats, rp, n) != 0)
+ ret = -1;
}
if (tftp_stats.amount > 0)
printstats("Received", verbose, &tftp_stats);
- return;
+ return ret;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Feb 11, 6:08 AM (10 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16589699
Default Alt Text
D38958.diff (4 KB)
Attached To
Mode
D38958: tftp: Correctly propagate transfer errors.
Attached
Detach File
Event Timeline
Log In to Comment