From patchwork Mon Jan 8 10:04:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Bulwahn X-Patchwork-Id: 10149219 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2387F601BE for ; Mon, 8 Jan 2018 10:04:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 156D01FF2D for ; Mon, 8 Jan 2018 10:04:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0924127CF9; Mon, 8 Jan 2018 10:04:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2161FF2D for ; Mon, 8 Jan 2018 10:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932250AbeAHKEe (ORCPT ); Mon, 8 Jan 2018 05:04:34 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:35433 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932202AbeAHKEb (ORCPT ); Mon, 8 Jan 2018 05:04:31 -0500 Received: by mail-wr0-f193.google.com with SMTP id n9so238694wrg.2; Mon, 08 Jan 2018 02:04:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h6ZXdBSSmdNrrxv7nJ/8d46qFuymB7BUoKzyVW1jclo=; b=ZOztL7pVAfTEzPhRgTM6DzmlvcgFieGjNhjCzbG8Z/YLG+oU8UeQO0pH5lVS5/z+aG SpR8qVhCdFOrMJa2mCgakO3gjGFX3DmfLGOzrqVW5ry/BCasK3Xf6Mgz3c3uFLKvABZu GS1DuAQPCaBxXbmb5Rucw6K9sFucYvZgJNObaepdApLFHG/jp6tuTwmrQpiVNcQVqBSa ttqQVRQ++SA8Aio13wvQcPzESC2kJQ5lZ2Y+HFxnaVd5IdN9hknHdqWZYdqGB7EjNwpM XxRo8v9ILqxCy6wNQRQUoeJc8zQjKRXE4y9u9/l5fFhTcHthKsfsCsBme45RKMvKsXpB s84Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h6ZXdBSSmdNrrxv7nJ/8d46qFuymB7BUoKzyVW1jclo=; b=WpHC0x1ngfElFsm9w+bdgd9bBXIZXLsQqfUoAl0WYurFJHitN47lvaNFV2QhSTFwf4 wzlWaOxBhCNhT++XQRM1fnEDud2YlGkFtLDGSB63hv1c7TmQwmsekxSIBEFGBeJB3dsZ qzT8JrgvgZbsWEy603EW41ZVrKSorHSQwJL9SrBlu801uK0qoei1bIabBw6IEuhCFvsg a+wW3e/8rQrzHNDFvSR5l1St8BquqqGax/SiVptunH377yFvckhv52idY8n0onleCxZX mGPKLq7Ri8swvl2mOKKTi1ETXezCcQALpLpZ39XJEpCQuAtD5lzrSCNzdOxPnfiF62B2 ucaw== X-Gm-Message-State: AKGB3mKfJHEGDMqL2kQIObUGej/2OqRdsdSSMtY0SQvzFWTGI0wG+sMR fq2yySl+r/8RZJh7V6VTCRhoVpTD X-Google-Smtp-Source: ACJfBotTupaXWXLODSoIT0BgytvuqWl6TQ2s2+D3P+0daEVOxtz/Z2Yhz48ifR/tvYO2aLW8IXfQ4A== X-Received: by 10.223.186.83 with SMTP id t19mr9536778wrg.64.1515405869795; Mon, 08 Jan 2018 02:04:29 -0800 (PST) Received: from hulk.bmw-carit.intra ([145.253.130.2]) by smtp.gmail.com with ESMTPSA id h16sm7679294wre.43.2018.01.08.02.04.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 02:04:28 -0800 (PST) From: Lukas Bulwahn To: linux-kbuild@vger.kernel.org Cc: lukas.bulwahn@gmail.com, Nicholas Mc Guire , sil2review@lists.osadl.org, Sam Ravnborg , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v3] fixdep: exit with error code in error branches of do_config_file() Date: Mon, 8 Jan 2018 11:04:01 +0100 Message-Id: <1515405841-2041-1-git-send-email-lukas.bulwahn@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1513883429-9527-1-git-send-email-lukas.bulwahn@gmail.com> References: <1513883429-9527-1-git-send-email-lukas.bulwahn@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP do_config_file() should exit with an error code on internal run-time errors, and not return if it fails as then the error in do_config_file() would go unnoticed in the current code and allow the build to continue. The exit with error code will make the build fail in those very exceptional cases. If this occurs, this actually indicates a deeper problem in the execution of the kernel build process. Now, in these error cases, we do not explicitly free memory and close the file handlers in do_config_file(), as this is covered by exit(). This issue in the fixdep script was introduced with its initial implementation back in 2002 by the original author Kai Germaschewski with this commit 04bd72170653 ("kbuild: Make dependencies at compile time") in the linux history git tree, i.e., git://git.kernel.org/pub/scm/linux/kernel/git/history/history.git. This issue was identified during the review of a previous patch that intended to address a memory leak detected by a static analysis tool. Link: https://lkml.org/lkml/2017/12/14/736 Suggested-by: Nicholas Mc Guire Suggested-by: Masahiro Yamada Signed-off-by: Lukas Bulwahn --- compile tested on top of next-20180108 with clang and gcc Changes in v2: - no code change; only include proper Fixes tag and explain it Changes in v3: - Clarify history commit reference and dropped Fixes tag - Do not error on empty files (reverts one hunk of v2) scripts/basic/fixdep.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bbf62cb..86a61d6 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -290,13 +290,11 @@ static void do_config_file(const char *filename) map = malloc(st.st_size + 1); if (!map) { perror("fixdep: malloc"); - close(fd); - return; + exit(2); } if (read(fd, map, st.st_size) != st.st_size) { perror("fixdep: read"); - close(fd); - return; + exit(2); } map[st.st_size] = '\0'; close(fd);