From patchwork Fri Oct 28 08:36:38 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: 9401541 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 E60E660588 for ; Fri, 28 Oct 2016 08:37:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D86402A650 for ; Fri, 28 Oct 2016 08:37:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD3D72A652; Fri, 28 Oct 2016 08:37:17 +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 7426F2A650 for ; Fri, 28 Oct 2016 08:37:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934554AbcJ1IhQ (ORCPT ); Fri, 28 Oct 2016 04:37:16 -0400 Received: from mout.web.de ([212.227.15.14]:63783 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934755AbcJ1IhP (ORCPT ); Fri, 28 Oct 2016 04:37:15 -0400 Received: from [192.168.1.2] ([77.182.172.137]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0LuMAJ-1d09IX1z8B-011icv; Fri, 28 Oct 2016 10:36:38 +0200 Subject: [PATCH 06/10] scripts/basic/fixdep: Complete error handling in do_config_file() 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: Date: Fri, 28 Oct 2016 10:36:38 +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:ecScdbAVQe7IoT2cHXYElI/k8Jj8JkGoYrtIQ6vpeqwYUHu+0Au VryymiJr1Nf7HRVMlwm/cv5iIwnshmEioaqFSYnZz5dw3aozfDmSeV4KJ6z4BOllmIxhBMb RzhlyyQau0b0AnA7qURD/VrfIzPNFsiFC2hWvE3YYLWyHL6tq//BdfXEN0cueopeqnV0l34 kKqKWKptg/KD0NWOVK1FQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:BLdCzpIGa+o=:hH4om4M1txgZLkmYKsZ6OM xCO6l4DJywAWsqvlHGrDXMaT539FGpoB8/beORBCDL11/SjZQ1rpGx+EWANoCD3T16sL0Z9eT zPxVOVGsPtAfiT7oUdPjPHXmF/Pah6HLPEjFgU4Qd8VAWgg7eNZyy3cPnpT/gkvcQZ55mUhNG j3CATcS41kFMGay58Zdgs90GOS+PEZEq6rn1sUWBKXyWXY0WZK8fLoWaYuRhOSfafwdTzfl61 wmL1DTNS1zPR52cUSHXWdpZwimW5TfGK61bZ9pdyP5X6DD2BD3lc0hfkyZHkzlDOfFZpLWmiw /JOtXgDwXWtxW8AU9ymKEE1eStpf44SRSfCl8mat9P58UJNjYAKMxqVaKEUA1kjx8tua0ExlK 9oihgvnFJ6yeVJDxDhQAxjb+PTKxj3ZgEiSj3FovrZcGob4wT1xSkNvWcYRFfv5r9s2SsSvnf ka25axYpkS8lKdSkiPPVYw7FIk1Xk8N9yvjLWcz5FD5+Pfn+0BM+eZBOS49xxKFMOztfWMlAH Bw13fogl+GASP/HRc2DuVcfqVluzXlLlc2igPRZk789qjGvmYiuM0/+vQgOaoq97nJk2XM2Kp HfDlIMIbzRNF7GrXlfpcx3XFfsQOhGvIZYVSUAU0rXXlKYOFV1ASjHKkP1meoEDzVdmj4xC+A gyswlQf+pfigiiIHTEd5E5dhI+5fLFsgdhelEoYrhRBu7UWUHk/ZdmuM1+7Iwdg2HC7Co7kwi V6E8Gawjui5WdXxLJbVY1zFzS6FIphVxxS5MdrdQmX8MXG6TGYTti7Xg3ND1c0hYeyIQwG/sh cpIareQ 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 22:02:42 +0200 Return values were not checked from four calls of the function "close". 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 | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 5f6a4f4..be0fdaa 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c @@ -284,27 +284,33 @@ static void do_config_file(const char *filename) perror(filename); exit(2); } - if (st.st_size == 0) { - close(fd); - return; - } + if (st.st_size == 0) + goto close_fd; map = malloc(st.st_size + 1); if (!map) { perror("fixdep: malloc"); - close(fd); - return; + goto close_fd; } if (read(fd, map, st.st_size) != st.st_size) { perror("fixdep: read"); - close(fd); - return; + goto close_fd; } map[st.st_size] = '\0'; - close(fd); - + if (close(fd)) + goto close_failure; parse_config_file(map); - free(map); + return; +close_fd: + if (close(fd)) { +close_failure: + { + int code = errno; + + perror("fixdep: close"); + exit(code); + } + } } /*