From patchwork Fri Oct 28 08:32:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9401515 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 8F94A60588 for ; Fri, 28 Oct 2016 08:33:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FBBE28DA4 for ; Fri, 28 Oct 2016 08:33:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 740D92A639; Fri, 28 Oct 2016 08:33:02 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 19D9328DA4 for ; Fri, 28 Oct 2016 08:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759533AbcJ1IdB (ORCPT ); Fri, 28 Oct 2016 04:33:01 -0400 Received: from mout.web.de ([212.227.15.3]:61239 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756158AbcJ1IdA (ORCPT ); Fri, 28 Oct 2016 04:33:00 -0400 Received: from [192.168.1.2] ([77.182.172.137]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0M0Qxx-1cu3Ul1EVR-00uWip; Fri, 28 Oct 2016 10:32:50 +0200 Subject: [PATCH 02/10] scripts/basic/fixdep: Complete error handling in print_deps() To: linux-kbuild@vger.kernel.org, Michal Marek References: <72e07814-56e9-505a-d660-91ff20b6efea@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <9402cf24-9e3e-95d0-c3e6-a51631eda20e@users.sourceforge.net> Date: Fri, 28 Oct 2016 10:32:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <72e07814-56e9-505a-d660-91ff20b6efea@users.sourceforge.net> X-Provags-ID: V03:K0:wAF4LtvtqJlqWoaN9POhG6JOeOcFZI48IvACT2melic2sMTvUyR x8Uq0/DLD3m5VrAQWnhCDp78+jSAr8qeauSnJYOEFaxCGBNujvsHUwmJgRl6fjyjwClD6dD JEeDRZsV4iwGPfa1bZQBYKjMBg8Nrk3yapAc0JJAVOhwRtuXxAb7BVHXVOpm2EMAaez1gj3 wGm5o0GQYorm3WGw+w8kw== X-UI-Out-Filterresults: notjunk:1; V01:K0:SSpxOXVgMgM=:Q49hlu/hU42yVYI7wcvz7z zp+UdsqzjLXkzdE+x9OUgfz/ZN6UWg6I0RvO/eB0UA0iILnyQWQM5wdXp4c2DbsI9c561HxEs L5YQGE8Z5Ps7YUldmgdMgr5kRLqCmQH8u2tsph5Sas1bsRfGJ7WTHDX1YdN9cCw7nyzGjCPe4 S0r60fYrkq4uTd/tdokwId9smQKrWyfzN3t01SC1qGXD6GlSTDt+bAwImc/siX1jZQXAWr8Cn pTYI4Xpj7AdHJwOMMYu21zQF9exblrRjKq9AXZpXFo2A5VsEXyHVO7mI2gOVnSFVNJavQIpzM S8GtAkIlXD20fg5AYEhg21C1D4UGWluT1WWG2YhlCajg7cTwfA2F3qrRm/FMnaPjB5buI8Ukz foANyABBK8t8ihlSxZ0nE8OUOsOF4mBQCI/Jek3UH9l2u8la309N8KEuG23dpPHGV2xVLutgF Fo7oR+4UoweE/5RSI8snhysnesdGp1Lvv4NGJLfHlDmTWoI68TYWgfFcbooreV7PT6Zqj4AvC iMJTDiWYTBEQ9kzHV2ReN0rqGPgffiUD4rqCjU61iqedeOfHoRDWttbz/F9C14zRbJi6EbxVQ m2Qfrtbq59dJqIKhss8oybDZYnXfgS3cA+VWTG8If9skua4rBPFqbv4rcNQaSdF9tqtHHKFWg xAdzRJX4SFvA6mmBhk5HpHrraImbF9wSHvnD/ZJQAbTe3YF/e9lo08aXtD4FwonCmSzt3zO5y PQ1hDXZhl9w2IDzMroGQlx2LDyVyJ63zX++cSK4b2WHUQlkfsLhJKUAJnY3NeWtHAeMObhBK0 PK3ZJWf 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 From: Markus Elfring Date: Thu, 27 Oct 2016 18:08:30 +0200 Return values were not checked from calls of the functions "close" and "munmap". This issue was detected also by using the Coccinelle software. Add a bit of exception handling there. Signed-off-by: Markus Elfring --- scripts/basic/fixdep.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index fff818b..c9ce3e3 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -113,6 +113,7 @@ #include #include #include +#include int insert_extra_deps; char *target; @@ -413,21 +414,24 @@ static void print_deps(void) } if (st.st_size == 0) { fprintf(stderr,"fixdep: %s is empty\n",depfile); - close(fd); - return; + goto close_fd; } map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if ((long) map == -1) { perror("fixdep: mmap"); - close(fd); - return; + goto close_fd; } parse_dep_file(map, st.st_size); - - munmap(map, st.st_size); - - close(fd); + if (munmap(map, st.st_size)) + perror("fixdep: munmap"); +close_fd: + if (close(fd)) { + int code = errno; + + perror("fixdep: close"); + exit(code); + } } int main(int argc, char *argv[])