Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 May 2026 09:03:42 +0000
From:      Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: ddd16aef6b03 - stable/14 - tftp: Close files when we're done with them
Message-ID:  <6a16b36e.25574.33420411@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/14 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=ddd16aef6b03f83a42f8b547563e0deb2d6cc1a4

commit ddd16aef6b03f83a42f8b547563e0deb2d6cc1a4
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-05-22 17:57:12 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-05-27 09:03:29 +0000

    tftp: Close files when we're done with them
    
    Also, delete the file we created if receiving it failed.
    
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D57071
    
    (cherry picked from commit 29351335704e39ce3ca09c528d534c7898bbdc2c)
---
 usr.bin/tftp/main.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
index 32eee2fb9afd..3db01f53dd78 100644
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -597,8 +597,11 @@ get(int argc, char *argv[])
 			if (verbose)
 				printf("getting from %s:%s to %s [%s]\n",
 				    hostname, src, cp, mode);
-			if (recvfile(peer, port, fd, src, mode) != 0)
+			if (recvfile(peer, port, fd, src, mode) != 0) {
+				(void) unlink(cp);
 				txrx_error = 1;
+			}
+			close(fd);
 			break;
 		}
 		cp = tail(src);         /* new .. jdg */
@@ -610,8 +613,11 @@ get(int argc, char *argv[])
 		if (verbose)
 			printf("getting from %s:%s to %s [%s]\n",
 			    hostname, src, cp, mode);
-		if (recvfile(peer, port, fd, src, mode) != 0)
+		if (recvfile(peer, port, fd, src, mode) != 0) {
+			(void) unlink(cp);
 			txrx_error = 1;
+		}
+		close(fd);
 	}
 }
 


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a16b36e.25574.33420411>