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 @@ -102,6 +102,7 @@ n = send_wrq(peer, name, mode); if (n > 0) { printf("Cannot send WRQ packet\n"); + txrx_error = 1; return; } @@ -131,10 +132,12 @@ } if (i == 12) { printf("Transfer timed out.\n"); + txrx_error = 1; return; } if (rp->th_opcode == ERROR) { printf("Got ERROR, aborted\n"); + txrx_error = 1; return; } @@ -146,6 +149,7 @@ if (!options_rfc_enabled) { printf("Got OACK while options are not enabled!\n"); send_error(peer, EBADOP); + txrx_error = 1; return; } @@ -154,17 +158,17 @@ if (read_init(fd, NULL, mode) < 0) { warn("read_init()"); + txrx_error = 1; return; } block = 1; - tftp_send(peer, &block, &tftp_stats); + if (tftp_send(peer, &block, &tftp_stats) != 0) + txrx_error = 1; read_close(); if (tftp_stats.amount > 0) printstats("Sent", verbose, &tftp_stats); - - txrx_error = 1; } /* @@ -202,6 +206,7 @@ n = send_rrq(peer, name, mode); if (n > 0) { printf("Cannot send RRQ packet\n"); + txrx_error = 1; return; } @@ -231,15 +236,18 @@ } if (i == 12) { printf("Transfer timed out.\n"); + txrx_error = 1; return; } if (rp->th_opcode == ERROR) { tftp_log(LOG_ERR, "Error code %d: %s", rp->th_code, rp->th_msg); + txrx_error = 1; return; } if (write_init(fd, NULL, mode) < 0) { warn("write_init"); + txrx_error = 1; return; } @@ -251,6 +259,7 @@ if (!options_rfc_enabled) { printf("Got OACK while options are not enabled!\n"); send_error(peer, EBADOP); + txrx_error = 1; return; } @@ -259,13 +268,16 @@ n = send_ack(peer, 0); if (n > 0) { printf("Cannot send ACK on OACK.\n"); + txrx_error = 1; return; } block = 0; - tftp_receive(peer, &block, &tftp_stats, NULL, 0); + if (tftp_receive(peer, &block, &tftp_stats, NULL, 0) != 0) + txrx_error = 1; } else { block = 1; - tftp_receive(peer, &block, &tftp_stats, rp, n); + if (tftp_receive(peer, &block, &tftp_stats, rp, n) != 0) + txrx_error = 1; } if (tftp_stats.amount > 0)