Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp109522ybg; Mon, 8 Jun 2020 17:52:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNDn4S7ZeuoDyUQBQTSUNlIUWwuPTXDXjJlXwRcgM0sjK2CzHOjvcPzeajBU5ECrr5aRCS X-Received: by 2002:a17:906:7208:: with SMTP id m8mr7897570ejk.544.1591663929475; Mon, 08 Jun 2020 17:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591663929; cv=none; d=google.com; s=arc-20160816; b=BWkMpe/NJeGPvkSfEui35S8Gt9JEw3AUMjN8fH5mt1tl2og2ROmPHWrb5XwYNmL+QP klD8XK5wHiKDxO0XMo2EFaSoGrmv7fgb8+QHia6es0htGGC1hIE3AA8qcbzwQ8pbpFio JAL1CyB1N/JULdngC6t630F0kBsVhaQUqXQpRygR8144PkoYWWKEhvzse5WYjBecg0Uy uA6NgYIPzglWTiHulTiVx77yNrncb3QYFPdcBO4tcIBtqMyWq04imOlbbPBm8ELwIMWa 0bmC6PJ9xlPpkD3/2eLKI+DsmDkpwDjWhxrqxKhJcf6bCiB0lHxo4OJ2ioL8KJTnSIwY fg3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oYtMCjyNpZtIjED0tkxdJdFq0O9rJGTaym2xN9SR8eM=; b=RSXVhGwEg0C2K5+JqG2BnWz1UXwxbxPGuRflGBr0goyf4a7wSvU3BxqD+nvMFV7ZyH Z+aTGVbGOjpGP/dQzP6zYN2r9nJ+8uLOOve36MoYORuB8zXdLnkBCb29rkELHBr12A4p ZgnjUf3RruRmAI5ctrHoT1XBTC5cs4bI/shrLlB9bVGXSLbAmK3A9i85PRVZp/FyiXLA 3uzi87QaQOVlpdG96JDOUkltrpzX0FX+hM/96cI49RopxUFDj1NTQ65SEPOaIA9APL4b wWQKSMvM61mMaSSjbPHqINh9gYKWxAa5pBP6mr074dvi9J0chFkQnJAR6agtHIAoANA3 ss/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qmF7AeJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si9590293edv.486.2020.06.08.17.51.46; Mon, 08 Jun 2020 17:52:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qmF7AeJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730560AbgFIAsC (ORCPT + 99 others); Mon, 8 Jun 2020 20:48:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:57858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728850AbgFHXLJ (ORCPT ); Mon, 8 Jun 2020 19:11:09 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A53242100A; Mon, 8 Jun 2020 23:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657869; bh=/747nDpUrA+HrhPyngwEof3PhSh74KiCISRw9/z8wE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qmF7AeJLJF5fHHJNCmoCNi9bwdDc4NcfuhjJxHP6u24Zef4lXnLnkoeGzGvjsaOZ+ N06r9YHSrqzHn2VRX7A0rist5bCRSUtzRy22iDDe9ZlW1rEFzgRiuHGUegPLck+9+g uNn9UR2tGID2/9QwjAInEOIBozm+hptSC1wjfX+0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kaige Li , Thomas Bogendoerfer , Sasha Levin , linux-mips@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 230/274] MIPS: tools: Fix resource leak in elf-entry.c Date: Mon, 8 Jun 2020 19:05:23 -0400 Message-Id: <20200608230607.3361041-230-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kaige Li [ Upstream commit f33a0b941017b9cb5a4e975af198b855b2f2b455 ] There is a file descriptor resource leak in elf-entry.c, fix this by adding fclose() before return and die. Signed-off-by: Kaige Li Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/tools/elf-entry.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/mips/tools/elf-entry.c b/arch/mips/tools/elf-entry.c index adde79ce7fc0..dbd14ff05b4c 100644 --- a/arch/mips/tools/elf-entry.c +++ b/arch/mips/tools/elf-entry.c @@ -51,11 +51,14 @@ int main(int argc, const char *argv[]) nread = fread(&hdr, 1, sizeof(hdr), file); if (nread != sizeof(hdr)) { perror("Unable to read input file"); + fclose(file); return EXIT_FAILURE; } - if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG)) + if (memcmp(hdr.ehdr32.e_ident, ELFMAG, SELFMAG)) { + fclose(file); die("Input is not an ELF\n"); + } switch (hdr.ehdr32.e_ident[EI_CLASS]) { case ELFCLASS32: @@ -67,6 +70,7 @@ int main(int argc, const char *argv[]) entry = be32toh(hdr.ehdr32.e_entry); break; default: + fclose(file); die("Invalid ELF encoding\n"); } @@ -83,14 +87,17 @@ int main(int argc, const char *argv[]) entry = be64toh(hdr.ehdr64.e_entry); break; default: + fclose(file); die("Invalid ELF encoding\n"); } break; default: + fclose(file); die("Invalid ELF class\n"); } printf("0x%016" PRIx64 "\n", entry); + fclose(file); return EXIT_SUCCESS; } -- 2.25.1