From patchwork Thu Dec 21 19:10:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Bulwahn X-Patchwork-Id: 10128295 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 258AE60318 for ; Thu, 21 Dec 2017 19:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C03F29DDC for ; Thu, 21 Dec 2017 19:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F10F129DDF; Thu, 21 Dec 2017 19:10:50 +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=ham 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 17DA729DDC for ; Thu, 21 Dec 2017 19:10:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752509AbdLUTKt (ORCPT ); Thu, 21 Dec 2017 14:10:49 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:40964 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752433AbdLUTKs (ORCPT ); Thu, 21 Dec 2017 14:10:48 -0500 Received: by mail-wr0-f196.google.com with SMTP id p69so17185596wrb.8; Thu, 21 Dec 2017 11:10:47 -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=WVlAgKt1RUfoFKoxr7UBiRm+XuJtOvdSCSTaUeQUa4E=; b=oUFPgLZI+lzLeM36QATuRdz6hy1O0Thsl+m7oW4tKVUaBnAhNkH0EATWEOGl1RlReP byTY+TekhXuWVpNuNGaIKqrgC3spIxj45RoSQhqZcb2+778Q8KkNalmz9CIB7/TzGGI2 yTPjAKIuNZ9Pa+eUs7KFVLCQJBtp5IlrhrvQsZmUkYgyxs9MgraAb1dsW1wB1GNfQSBE aZG3w8tAT5TxhHBMwu7LBZe2n/7sGbzEupxM23MaJvcIn4c0GBPq1Nad+0kX2UjSyCE6 CA9KelHe7d16/0CMjm+RQSsXVfjQ94K10qJmFZ+cQPq0cJ3yKwvW3nyLT5z/QG0JVf0Y tffQ== 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=WVlAgKt1RUfoFKoxr7UBiRm+XuJtOvdSCSTaUeQUa4E=; b=KEFXwErHFg2FXcv4HE1cbL+ApS8F5IatndcIZTfpbGlyO3ZAjHm11qd4E5TnCI7r6K NapENIrPCQosD7vz1mr9gd/VhrUXqY79I2kOsZ4KZHYXjY9JweJPxbAO89iozq2KXwjW XPRplq5zpb+4paqyi7ColHrz44T+k//1OGZqgGlDfyFASQEr6sngDY55guG7bm1cLe61 azGI8Sp7NyPywRiqYyErBKmMCiuZOmMahn3xCujOZEFwPyMoRFCKdTX3Ve//NDlC1Dlo 8YTcDbdp+iZUXDGG6vagoRWfQ0HlsnYmjzDFv7W+0anoml5EBct3Id58OiXbh6wTWIAb JOsA== X-Gm-Message-State: AKGB3mKOKEl0AF8ff7p8DDX4L6Y9D+bePcPZXKtS4ialFCLnpQipDkYk hHYJdXFo9PggGYl/qsLkHii1Llbw X-Google-Smtp-Source: ACJfBov+j+2+ArP7tVlO1GCIpEunlZ6zmbQFMDWQryzVyvFWl2HI3eQTEVKbxD3QlG3Kqa310B2tWw== X-Received: by 10.223.153.151 with SMTP id y23mr13342380wrb.130.1513883446938; Thu, 21 Dec 2017 11:10:46 -0800 (PST) Received: from hsp.bmw-carit.intra ([145.253.130.2]) by smtp.gmail.com with ESMTPSA id g78sm11792904wmc.30.2017.12.21.11.10.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Dec 2017 11:10:46 -0800 (PST) From: Lukas Bulwahn To: linux-kbuild@vger.kernel.org Cc: lukas.bulwahn@gmail.com, Nicholas Mc Guire , sil2review@lists.osadl.org, Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH v2] fixdep: exit with error code in error branches of do_config_file() Date: Thu, 21 Dec 2017 20:10:29 +0100 Message-Id: <1513883429-9527-1-git-send-email-lukas.bulwahn@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513801623-19069-1-git-send-email-lukas.bulwahn@gmail.com> References: <1513801623-19069-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, 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, that the function exists, 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"). 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 Fixes: 04bd72170653 ("kbuild: Make dependencies at compile time") Suggested-by: Nicholas Mc Guire Suggested-by: Masahiro Yamada Signed-off-by: Lukas Bulwahn --- compile tested on top of next-20171220 with clang and gcc Change in v2: - no code change; only include proper Fixes tag and explain it scripts/basic/fixdep.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index bbf62cb..4274610 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -284,19 +284,18 @@ static void do_config_file(const char *filename) exit(2); } if (st.st_size == 0) { - close(fd); - return; + fprintf(stderr, "fixdep: error empty file config file: "); + perror(filename); + exit(2); } 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);