From patchwork Thu Apr 26 08:26:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 904919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 40Wqst4LCPz9rxx; Thu, 26 Apr 2018 18:26:42 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fBcEi-0002nR-E0; Thu, 26 Apr 2018 08:26:40 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1fBcEh-0002nJ-Kh for fwts-devel@lists.ubuntu.com; Thu, 26 Apr 2018 08:26:39 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1fBcEh-0003sT-CE; Thu, 26 Apr 2018 08:26:39 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] acpi: fan: fix potential null pointer dereference issue Date: Thu, 26 Apr 2018 09:26:39 +0100 Message-Id: <20180426082639.25299-1-colin.king@canonical.com> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" From: Colin Ian King Check for non-null info->type before dereferencing it with a strcmp. Detected by CoverityScan, CID#1390651 ("Null pointer dereferences") Fixes: 0eb85f83c260 ("fan: cur_state == -1 is valid for intel_powerclamp") Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/acpi/fan/fan.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/acpi/fan/fan.c b/src/acpi/fan/fan.c index 298d3a13..edd947e8 100644 --- a/src/acpi/fan/fan.c +++ b/src/acpi/fan/fan.c @@ -154,16 +154,19 @@ static int fan_test1(fwts_framework *fw) fwts_failed(fw, LOG_LEVEL_MEDIUM, "NoFanMaxState", "Fan %s present but has no max_state present.", info->name); - if (info->cur_state == -1 && strcmp(info->type, "intel_powerclamp")) - fwts_failed(fw, LOG_LEVEL_MEDIUM, "NoFanCurState", - "Fan %s present but has no cur_state present.", - info->name); - - if (info->type && - (info->max_state >= 0) && (info->cur_state >= 0)) - fwts_passed(fw, "Fan %s of type %s has max cooling state %d " - "and current cooling state %d.", - info->name, info->type, info->max_state, info->cur_state); + if (info->type) { + if ((info->cur_state == -1) && + strcmp(info->type, "intel_powerclamp")) + fwts_failed(fw, LOG_LEVEL_MEDIUM, "NoFanCurState", + "Fan %s present but has no cur_state present.", + info->name); + + if ((info->max_state >= 0) && (info->cur_state >= 0)) + fwts_passed(fw, "Fan %s of type %s has max cooling " + "state %d and current cooling state %d.", + info->name, info->type, info->max_state, + info->cur_state); + } } fwts_list_free(fans, free_fan_info);