From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 57EC0740046 for ; Tue, 22 Aug 2023 03:22:09 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PwnhaG9LK9Mour0hlcZArRqppSYeVzuXJvt0E+B9pKs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1692674527; v=1; b=Q3GdI7FW8qPXCeHpAwEch14eRWsXBe+IZ6ebYHGc4zaW+A1ihJd1N+S2PMFWpOalFGUxMq4S 1bKy0Ay5/7Vme3FW4jp86B9I+0PtPGonh2jm/Iw8ct89t1cFIIn3CIu3UdyjLjkmV7DStno9rfW WWZVKpUsTgXp5DnJJqqj9+tw= X-Received: by 127.0.0.2 with SMTP id aoASYY7687511xnPG4oBFlC2; Mon, 21 Aug 2023 20:22:07 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.700.1692674524445818488 for ; Mon, 21 Aug 2023 20:22:07 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="354093272" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="354093272" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 20:22:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10809"; a="826173466" X-IronPort-AV: E=Sophos;i="6.01,191,1684825200"; d="scan'208";a="826173466" X-Received: from njayapra-mobl.gar.corp.intel.com ([10.67.145.115]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 20:22:05 -0700 From: "Jayaprakash, N" To: devel@edk2.groups.io Cc: Jayaprakash N , Rebecca Cran , Michael D Kinney , Kloper Dimitry Subject: [edk2-devel] [edk2-libc Patch 1/1] edk2-libc/StdLib: file descriptor leak in rename() Date: Tue, 22 Aug 2023 08:51:54 +0530 Message-Id: <20230822032154.2009-2-n.jayaprakash@intel.com> In-Reply-To: <20230822032154.2009-1-n.jayaprakash@intel.com> References: <20230822032154.2009-1-n.jayaprakash@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,n.jayaprakash@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: WW4iLEpSoSYfVAxGi75csFLpx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=Q3GdI7FW; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4529 rename() call leads to a function that makes open() for source file to be renamed. The resulting file descriptor is never closed. If you have to rename a couple of files this will quickly exhaust the descriptor table. The fix is trivial - just close the fd before returning from the function. Cc: Rebecca Cran Cc: Michael D Kinney Cc: Jayaprakash N Signed-off-by: Kloper Dimitry --- StdLib/LibC/Uefi/Devices/UefiShell/daShell.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c index 861765e..06fcc3b 100644 --- a/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c +++ b/StdLib/LibC/Uefi/Devices/UefiShell/daShell.c @@ -670,6 +670,7 @@ da_ShellRename( free(NewFileInfo); if(Status == EFI_SUCCESS) { // File has been successfully renamed. We are DONE! + close(OldFd); return 0; } errno = EFI2errno( Status ); @@ -688,6 +689,7 @@ da_ShellRename( else { errno = ENOMEM; } + close(OldFd); } return -1; } -- 2.40.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107942): https://edk2.groups.io/g/devel/message/107942 Mute This Topic: https://groups.io/mt/100888179/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-