From nobody Fri Mar 10 13:29:18 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PY6My6sPZz3xX6T; Fri, 10 Mar 2023 13:29:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PY6My6FrNz3RGy; Fri, 10 Mar 2023 13:29:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8ciKQtK5PDyp82s1qokXx68YQOQJAWXhkMK4dMTIxwE=; b=vktT/GggJk0CNdjiVmKDB4su0MUrdQDzmjO3vUSC8x8W69lflroH8JV4ZF08NTFK4lEfCd h5rjot2C1VR5c0OFPTh0cGfM1Wg0wi+TXZwS+P1gILX3eMbQfF/bE4FLV/q+nibynOe2pP gnM27ndfPsoONlSfmy0BqFEVVt+23elsFGLVqMX/nknQdEe7JHVY8lAcPWjGhOjnJ1HWgg UocSnB5sc2tUhb5kthX9/SYlUlmrgGzoePURQ4BUvnf5GVjW7kmfWd2W7VqIby7kyN33G3 CCJ70eCmaVJ4U18XL0ZpkJ/Fh+txfb2T5ZC0P9exz7qcDHrwZeaqMNwnfpQR3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1678454958; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8ciKQtK5PDyp82s1qokXx68YQOQJAWXhkMK4dMTIxwE=; b=L+IXNCcI2cg7/0KJQSmPeJvOdDADtYejaSdHV+/sT7b86Y6yGWeFYNKaC+wWT4uu5o5EAM xSpyUTeWvIC6EmhkbEkIKnfIySFqC91162h0SF8ycUvdyokQsZbIVIMz3BcRh76DumlWx+ 5gL4rHjM8q+B07Rd8H4VbYw9fdHidqZI5dRtD8Zf6felN9txH8t4J38LXQsfPgPA5ciSt7 YfaDHAA4lWpJd6jp51Is00rgGZsGOk4cD/dfFmuwRXn/jPgerC4j6ldagPwQCbhOkaLmgZ vQsxt/estmPOicxSyUewj4V6b+U5eIzNa/6U5u/Ug8/lSkEozzRRhCeDgurVpg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1678454958; a=rsa-sha256; cv=none; b=spJCaH8het3tODIUBURlpuAGqneDoBq2NjCkwX2VBWs5nmVnMMjEXBKmEh2ZYpFn09Mnc9 dqCYJZ3I82cdB9ZYuTUxDEWbtlG5zo5vKHPetCPZ9D2vQQy0aZty/wPRpxkYtBJngBvOZu sk2TYHyjy003vx3aoPxyucBzqg45QubuzPgRcnwKoxlOKD4fTqq/eCnBpDNgR2KSqUFFSN aYDWhXteQtFIcoDQYM2wyR+sZG1rTqK/ucLlOdgviAoXR0oxsdVuUcLZmSuEuElet+R3Tt T/Yx04U8ztWt6IBdwFlMtmh6my4IVJK698PH/6Gp8DgGmo3m0PTONux1wLSe7g== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PY6My5LVjzqDD; Fri, 10 Mar 2023 13:29:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32ADTIMC090072; Fri, 10 Mar 2023 13:29:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32ADTIFv090071; Fri, 10 Mar 2023 13:29:18 GMT (envelope-from git) Date: Fri, 10 Mar 2023 13:29:18 GMT Message-Id: <202303101329.32ADTIFv090071@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 92570f67c791 - main - tftp: Correctly propagate transfer errors. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 92570f67c7911126ce742a3dfe1b97046091ed0e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=92570f67c7911126ce742a3dfe1b97046091ed0e commit 92570f67c7911126ce742a3dfe1b97046091ed0e Author: Dag-Erling Smørgrav AuthorDate: 2023-03-10 13:24:28 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-03-10 13:25:16 +0000 tftp: Correctly propagate transfer errors. Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D38958 --- usr.bin/tftp/main.c | 14 +++++++++----- usr.bin/tftp/tftp.c | 44 +++++++++++++++++++++++--------------------- usr.bin/tftp/tftp.h | 5 ++--- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 05d8b31331f6..9cc18fbb0d5b 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -84,7 +84,7 @@ typedef struct sockaddr_storage peeraddr; 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 @@ put(int argc, char *argv[]) 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 @@ put(int argc, char *argv[]) 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 @@ get(int argc, char *argv[]) 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 @@ get(int argc, char *argv[]) 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.c b/usr.bin/tftp/tftp.c index 31fefd8f22e2..d5f36e77d853 100644 --- a/usr.bin/tftp/tftp.c +++ b/usr.bin/tftp/tftp.c @@ -68,11 +68,11 @@ __FBSDID("$FreeBSD$"); /* * 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 @@ xmitfile(int peer, char *port, int fd, char *name, char *mode) n = send_wrq(peer, name, mode); if (n > 0) { printf("Cannot send WRQ packet\n"); - return; + return -1; } /* @@ -131,11 +131,11 @@ xmitfile(int peer, char *port, int fd, char *name, char *mode) } 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 @@ xmitfile(int peer, char *port, int fd, char *name, char *mode) 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 @@ xmitfile(int peer, char *port, int fd, char *name, char *mode) 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 @@ recvfile(int peer, char *port, int fd, char *name, char *mode) n = send_rrq(peer, name, mode); if (n > 0) { printf("Cannot send RRQ packet\n"); - return; + return -1; } /* @@ -231,16 +231,16 @@ recvfile(int peer, char *port, int fd, char *name, char *mode) } 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 @@ recvfile(int peer, char *port, int fd, char *name, char *mode) 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 @@ recvfile(int peer, char *port, int fd, char *name, char *mode) 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; } diff --git a/usr.bin/tftp/tftp.h b/usr.bin/tftp/tftp.h index 26e5652d0fdd..680ea2ea4fb6 100644 --- 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;