From patchwork Tue Oct 8 17:19:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach Brown X-Patchwork-Id: 3004491 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2B89EBF924 for ; Tue, 8 Oct 2013 17:19:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 22794201BA for ; Tue, 8 Oct 2013 17:19:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3874B2011D for ; Tue, 8 Oct 2013 17:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755504Ab3JHRTo (ORCPT ); Tue, 8 Oct 2013 13:19:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62246 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753131Ab3JHRTn (ORCPT ); Tue, 8 Oct 2013 13:19:43 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r98HJdsh021401 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Oct 2013 13:19:39 -0400 Received: from localhost (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r98HJcIA013367 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 8 Oct 2013 13:19:39 -0400 Date: Tue, 8 Oct 2013 10:19:38 -0700 From: Zach Brown To: Stefan Behrens Cc: linux-btrfs@vger.kernel.org, Eric Sandeen , David Sterba Subject: Re: [PATCH 02/12] btrfs-progs: check fopen failure in cmds-send Message-ID: <20131008171938.GL25712@lenny.home.zabbo.net> References: <1381182185-10896-1-git-send-email-zab@redhat.com> <1381182185-10896-3-git-send-email-zab@redhat.com> <5253C552.7080609@giantdisaster.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5253C552.7080609@giantdisaster.de> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP > > @@ -72,6 +72,11 @@ int find_mount_root(const char *path, char **mount_root) > > close(fd); > > > > mnttab = fopen("/proc/mounts", "r"); > > + if (!mnttab) { > > + close(fd); > > + return -errno; > > close() can modify errno. > > And close(fd) is already called 4 lines above. You didn't run the static > code analysis again after applying your patch :) OK, here's a less dumb attempt: - z From f8a3425c184a55e0c254143e520e60a6856c27da Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 4 Oct 2013 15:38:18 -0700 Subject: [PATCH] btrfs-progs: check fopen failure in cmds-send Check for fopen() failure. This shows up in static analysis as a possible null pointer derference. Signed-off-by: Zach Brown Laughed-at-by: Stefan Behrens --- cmds-send.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmds-send.c b/cmds-send.c index 374d040..81b3e49 100644 --- a/cmds-send.c +++ b/cmds-send.c @@ -72,6 +72,9 @@ int find_mount_root(const char *path, char **mount_root) close(fd); mnttab = fopen("/proc/mounts", "r"); + if (!mnttab) + return -errno; + while ((ent = getmntent(mnttab))) { len = strlen(ent->mnt_dir); if (strncmp(ent->mnt_dir, path, len) == 0) {