From nobody Thu Nov 17 16:41:30 2022 X-Original-To: dev-commits-src-main@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 4NClzt54r9z4hjDD; Thu, 17 Nov 2022 16:41:30 +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 4NClzt4f2zz3qWM; Thu, 17 Nov 2022 16:41:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668703290; 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=IEZez+3ps7iHw6PgE2SqjiwFrLc013TpHB3TQRt6a8A=; b=CAo7dtJjFLv2dADEd48EHVseWI8JYNsg3MBuyNRCzMuy1+SPRBEBnCdN/mPPeIRd8ZwT9L 9e0lO5czw3NG1at4nO3jRxZIJMPkaYkcoS52EvTv5tY+4bI5MMs3cmAn2V5GkPSZfit8S1 QgBVEHExC7DDLKUReg2oKiQOhaCRgg/jSAkRsEbp8CpzAoy+oJvhj9QYbkskatZ5sFi0oO /Duo1vcmCIPZQOt0X5tkls54D4xzhzn6NKIXbQ9w+P+f5Gem9fd4fSScUNdbZinkoq0iKg rlKC/gPLKWm6lapFTALUr/UcY51ro/he+YwpQFRfkSVRCFJHJCzAtQOxRTAyAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668703290; 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=IEZez+3ps7iHw6PgE2SqjiwFrLc013TpHB3TQRt6a8A=; b=xC4sz5cOixAAqg6NzmJkxciiIDYsgh8oEbf+i+ooBYAovW/simbmfflC3rqDzBSPcmzclE HZc7H/Z3MsVSaLPZCsIBd1PJicBC9omdoIkO0oDEEMEEo/uRsfIdeSFP9wJoTZBX9LG5Q2 07yFE1Xfi180a6dWNGsXH/Rl5iTYkWIq+uPWlaLfCGKlyQgHPQwtjk/FQgQ/s6pJJLISdO Ww7HQIs7Zp18SrP9Bj7rAErz9/FMPs4u4vADEl2rmnbPaeqdN/qWOfe8WyXutWdUTdOCmV I5kRv3zcgDrQ14c+Lx0z6A5/ElygzgzMRb3/bjReYk+OvdwS+w9EaCFoaVaohg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668703290; a=rsa-sha256; cv=none; b=jR5mSIc1E2c4jTwa480l/huL4cYIdH2uwV8es7Mh5BrXSbu2CUciCtKuGxDLKvTHasSP+J Z0/dIay7DhtTHaNtFqCSKJeij+7ktb4q20qA5gInSEeMAuHD7ZSDktsRIhf9oAymYGjnGU YhhfgWo9G06Zx51JlanhV9Ax50+AuXnNqn/5KaoaG+N5YDnAld7iDHONTo8ZWbcpgmveqF OfSC4l7ZLy/XExZI5/u/JRpuZ84hBzr8Wai6PZww943t0OT3oojQlDOPn1l4A1tdfoq3jf BbL/QUG+bFPqcY/btTxjvvdGFGoQ3KpYPTIN86zWk4cq42ebvTjfWqZaQ8vbeg== 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 4NClzt3jBhznn4; Thu, 17 Nov 2022 16:41:30 +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 2AHGfUZW035886; Thu, 17 Nov 2022 16:41:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AHGfUvm035885; Thu, 17 Nov 2022 16:41:30 GMT (envelope-from git) Date: Thu, 17 Nov 2022 16:41:30 GMT Message-Id: <202211171641.2AHGfUvm035885@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: 9f9544fd92e6 - main - tftp: Fix buffer overflow and fd leak in multi-file PUT. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 9f9544fd92e606d13e228b713d3c4a7cad78575d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=9f9544fd92e606d13e228b713d3c4a7cad78575d commit 9f9544fd92e606d13e228b713d3c4a7cad78575d Author: Dag-Erling Smørgrav AuthorDate: 2022-11-17 16:15:04 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2022-11-17 16:26:24 +0000 tftp: Fix buffer overflow and fd leak in multi-file PUT. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37422 --- usr.bin/tftp/main.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 33546dc4ee23..b6d7bd2a0dcc 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -445,7 +445,7 @@ put(int argc, char *argv[]) { int fd; int n; - char *cp, *targ; + char *cp, *targ, *path; char line[MAXLINE]; struct stat sb; @@ -507,26 +507,32 @@ put(int argc, char *argv[]) } /* this assumes the target is a directory */ /* on a remote unix system. hmmmm. */ - cp = strchr(targ, '\0'); - *cp++ = '/'; for (n = 1; n < argc - 1; n++) { - strcpy(cp, tail(argv[n])); + if (asprintf(&path, "%s/%s", targ, tail(argv[n])) < 0) + err(1, "malloc"); + fd = open(argv[n], O_RDONLY); if (fd < 0) { warn("%s", argv[n]); + free(path); continue; } if (fstat(fd, &sb) < 0) { warn("%s", argv[n]); + close(fd); + free(path); continue; } asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); if (verbose) printf("putting %s to %s:%s [%s]\n", - argv[n], hostname, targ, mode); - xmitfile(peer, port, fd, targ, mode); + argv[n], hostname, path, mode); + xmitfile(peer, port, fd, path, mode); + close(fd); + + free(path); } }