Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1318207yba; Tue, 2 Apr 2019 06:47:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmVpQpOZ/BQYoLbYubyuJTgp6HZu9BJl9g2ibU+Ou7AHe6KlE4MTS+9qRwGb/31ZAKn62/ X-Received: by 2002:a62:1881:: with SMTP id 123mr68221575pfy.25.1554212832507; Tue, 02 Apr 2019 06:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554212832; cv=none; d=google.com; s=arc-20160816; b=Adq65U4FBYFUyXVXWqbIfG7h36AisZV+YHK6QjJpim6m5ZCmo7znd+Va2GuvS77M+e fABs6kZB5DhYivrqVQXTleqfztcnXAyE1RHdwf/Qz1m1hnwaSeoT0+RSrc7POsO/GMJv DVIShwcHuaqfSs5222y+i1cT5DDNpidY90i6PQW7bsPoHnDE3iv2EhrLvu3Yp8J17Chp udKToW0puDzjx5yobpLtlIZtLKhhjMMZeAReUvMA0gy/nu/YH8XpujlXbJb6P0JhYIl4 L6WDtxmM4D45sZNV5h0ytaJ6WP6nUkU+lETB5Rj1XTiFVZodP3k07Hht4WEozIqJJ6Qb wBXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=9WFxUWQP1OIx0cq41JtoLKFS2EWm6ZUkEiSXFYYQgh8=; b=AR0UbW4fzF3sR/YZ2P2GmQA33cwp8T9ou5QoF8ewyiuy/XrBelodunv+wiR4omuKXe 1K37disxbzCRJ3LQHH/8Nn3aLHhs6BNKXcsR+WyIg2wYZ+ojsD8k5+y6HWrKqLsEekis XaIpTxJry/pj/PYsBJAtNT3QLBPcXcczFRo1lURb+P8fLAye7aT2FO91rBZGznRUvdub FS4W5TwZxzYrVAyQEsDdmFdzOoZ5FF0rBYwuxi3sC/SXjqQ/OEzzf+8MsYO3ikwGZxo5 TnPaLL4LyXyGAlW2i9jIwqzxVG7Jn64GNOiE87R4TuSDd+ZSnZM9zFoVHMBiiBi77L1Q sgkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v4si11496203pgj.138.2019.04.02.06.46.57; Tue, 02 Apr 2019 06:47:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732141AbfDBNpt (ORCPT + 99 others); Tue, 2 Apr 2019 09:45:49 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43246 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731447AbfDBNkG (ORCPT ); Tue, 2 Apr 2019 09:40:06 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJdv-0002mn-4k; Tue, 02 Apr 2019 14:39:59 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdu-0004rr-5u; Tue, 02 Apr 2019 14:39:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "Colin Ian King" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 18/99] altera-stapl: check for a null key before strcasecmp'ing it In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 9ccb645683ef46e3c52c12c088a368baa58447d4 upstream. Currently the null check on key is occurring after the strcasecmp on the key, hence there is a potential null pointer dereference on key. Fix this by checking if key is null first. Also replace the == 0 check on strcasecmp with just the ! operator. Detected by CoverityScan, CID#1248787 ("Dereference before null check") Fixes: fa766c9be58b ("[media] Altera FPGA firmware download module") Signed-off-by: Colin Ian King Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: old code used strnicmp()] Signed-off-by: Ben Hutchings --- drivers/misc/altera-stapl/altera.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/misc/altera-stapl/altera.c b/drivers/misc/altera-stapl/altera.c index ef83a9078646..d2ed3b9728b7 100644 --- a/drivers/misc/altera-stapl/altera.c +++ b/drivers/misc/altera-stapl/altera.c @@ -2176,8 +2176,7 @@ static int altera_get_note(u8 *p, s32 program_size, key_ptr = &p[note_strings + get_unaligned_be32( &p[note_table + (8 * i)])]; - if ((strnicmp(key, key_ptr, strlen(key_ptr)) == 0) && - (key != NULL)) { + if (key && !strncasecmp(key, key_ptr, strlen(key_ptr))) { status = 0; value_ptr = &p[note_strings +