From patchwork Mon Oct 24 02:43:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9391299 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 670566089F for ; Mon, 24 Oct 2016 02:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D91F287BB for ; Mon, 24 Oct 2016 02:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4205828C0F; Mon, 24 Oct 2016 02:44:03 +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 D090E28C0B for ; Mon, 24 Oct 2016 02:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932546AbcJXCoA (ORCPT ); Sun, 23 Oct 2016 22:44:00 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:52263 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932339AbcJXCn7 (ORCPT ); Sun, 23 Oct 2016 22:43:59 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="922783" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 24 Oct 2016 10:43:49 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 94E7341B4BD9; Mon, 24 Oct 2016 10:43:44 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH 3/4] btrfs-progs: utils: Fix NULL pointer derefernces in string_is_numerical Date: Mon, 24 Oct 2016 10:43:34 +0800 Message-Id: <20161024024335.6770-3-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024024335.6770-1-quwenruo@cn.fujitsu.com> References: <20161024024335.6770-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 94E7341B4BD9.ADEF1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In get_running_kernel_version() function, we directly pass return pointer from strtok_r() to string_is_numberical(). Return pointer from strok_r() can be NULL, but string_is_numberical() can't handle it and will cause NULL pointer derefernces. Fix it by check if it's a NULL pointer first. Reported-by: David Sterba Resolves-Coverity-CID: 1374097 Signed-off-by: Qu Wenruo --- utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/utils.c b/utils.c index 3f54245..c135ac9 100644 --- a/utils.c +++ b/utils.c @@ -4015,6 +4015,8 @@ unsigned int get_unit_mode_from_arg(int *argc, char *argv[], int df_mode) int string_is_numerical(const char *str) { + if (!str) + return 0; if (!(*str >= '0' && *str <= '9')) return 0; while (*str >= '0' && *str <= '9')