From nobody Tue May 21 23:42:57 2024 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 4VkWFt0nZdz5L5sn; Tue, 21 May 2024 23:42:58 +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 4VkWFs5qkHz4gY9; Tue, 21 May 2024 23:42:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716334977; 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=knjsLndYunGLnSmzNWfPZtGDx4+XG0rUEZCwIJ+8KQo=; b=afUtpOJbByg5+jC3VVxD1ESgksYrvTQ4HcKddaysH6amAk61lrlhjQC0HEYVnZLLZpGdBS F6mXOZvm3CXMy/h1bvq+9lrriSGrD6Rz8B8WCsUesy3jXncAnythQetFlnoO6g7fex5dLs gqSmjOX55GS61dW7FuRmb5zjmR2VJlBDZdECxhqhDX/IrWeWLa8bBWW/pgOQnSpnOICPlm CvUnEfwElzGaihPUooz3Z/2ElfZ+Q8iGYdjscrpRhKKN9jW+uSDDoaVrCzNRQIKoPRcCgz UlQnucLOfXDPiNQBsMyWEF94fjixp01OqFXnBUrZfJKU0Y1NaoNjwZZwKjArtA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716334977; a=rsa-sha256; cv=none; b=xL0yaMuEm9xXPRN2yvmg+jzVV4aNqEuzF+L1cV1zw2zv0Q+T0K0N9tjb1CiTxB5n1fTDSo R1rk8bzq90xm5kylkZKy85M2KUYAjYebla11R/5Kmm0mY88a33UEb1kKVpihYTw+qivqaf LsmTixwN6i9EExzret2N6llBZxiSOmnGrnz7E515pUVEmb0SvhaqdI2k1itt4teZI3asVK uIxrljxNzF8jm7dewL35749nU+ca/22oK2ocshCjHKoHcJlDSJTosCAN+ghpVno4QnZC1s hqMvWaz6nh7jU1tX0iCPVsgY8iM2bt08FrbYBq7IVlPEk04wVFzlIqqKwnaZGA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716334977; 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=knjsLndYunGLnSmzNWfPZtGDx4+XG0rUEZCwIJ+8KQo=; b=stgY3OWVtS2jjoNsW1/fq4FvPuZfNgpVegxo9Wvd7kCJxIwWzVkF42CkjuFbxDph9GlbYN GV9XVhwYxnzOwv7hYr+AH5hRIV7IRlCrwbsgJHW50HTdbWt3+QcFAJfX1OG4LYNQPUfUco H7ODgM/uJlQAOIeOia9GOi1EzHErnakDgvTb1Ihd/zqB1Kl7HZXIcnfTKC8ASqT5GEpWGl Wi/b/de94a9u2sv/5u+IgY1QqGNeihHoWRgPN9sI26Wr6nuTaWv/RPDR4Dr13iiSnVqIsr nC2VL7VIH3U1e8FRGzi3mxlwrAuwRFh9HYMMVpssB4FcKoqz7DK5pzcKvaVxOw== 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 4VkWFs5RVYzhd6; Tue, 21 May 2024 23:42:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44LNgvIQ014480; Tue, 21 May 2024 23:42:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44LNgvql014477; Tue, 21 May 2024 23:42:57 GMT (envelope-from git) Date: Tue, 21 May 2024 23:42:57 GMT Message-Id: <202405212342.44LNgvql014477@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 408572a24e55 - main - libnvmf: avoid resource leak 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 408572a24e55a4c9ff9f81d1403ec0e055841264 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=408572a24e55a4c9ff9f81d1403ec0e055841264 commit 408572a24e55a4c9ff9f81d1403ec0e055841264 Author: Pierre Pronchery AuthorDate: 2024-05-16 14:34:34 +0000 Commit: Warner Losh CommitDate: 2024-05-21 23:41:04 +0000 libnvmf: avoid resource leak In nvmf_host_fetch_discovery_log_page(), the log variable may have been allocated on the heap during the first loop cycle, and should be free()'d before exiting upon errors. Reported by: Coverity CID: 1545034 Sponsored by: The FreeBSD Foundation Reviewed by: imp,jhb Pull Request: https://github.com/freebsd/freebsd-src/pull/1239 --- lib/libnvmf/nvmf_host.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/libnvmf/nvmf_host.c b/lib/libnvmf/nvmf_host.c index b78e2af65897..a0d95470d8ee 100644 --- a/lib/libnvmf/nvmf_host.c +++ b/lib/libnvmf/nvmf_host.c @@ -653,19 +653,23 @@ nvmf_host_fetch_discovery_log_page(struct nvmf_qpair *qp, log = NULL; for (;;) { error = nvmf_get_discovery_log_page(qp, 0, &hdr, sizeof(hdr)); - if (error != 0) + if (error != 0) { + free(log); return (error); + } nvme_discovery_log_swapbytes(&hdr); if (hdr.recfmt != 0) { printf("NVMF: Unsupported discovery log format: %d\n", hdr.recfmt); + free(log); return (EINVAL); } if (hdr.numrec > 1024) { printf("NVMF: Too many discovery log entries: %ju\n", (uintmax_t)hdr.numrec); + free(log); return (EFBIG); }