From patchwork Fri Apr 26 22:22:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 10919831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E25214DB for ; Fri, 26 Apr 2019 22:23:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02DE728E91 for ; Fri, 26 Apr 2019 22:23:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA1F728E9D; Fri, 26 Apr 2019 22:23:20 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 794C428E91 for ; Fri, 26 Apr 2019 22:23:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbfDZWWo (ORCPT ); Fri, 26 Apr 2019 18:22:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:54552 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbfDZWWn (ORCPT ); Fri, 26 Apr 2019 18:22:43 -0400 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 1hK9Es-0002bw-2W; Fri, 26 Apr 2019 22:22:38 +0000 From: Colin King To: Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] unicode: fix dereference of a potentially null pointer Date: Fri, 26 Apr 2019 23:22:37 +0100 Message-Id: <20190426222237.13209-1-colin.king@canonical.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 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: Colin Ian King The pointer 'tree' is deferenced when assigning pointer 'trie', however trie is being null checked a few lines later, so it could potentially be null. Fix the potential null pointer dereference by only dereferencing it after it has been null checked. Addresses-Coverity: ("Dereference before null check") Fixes: b08fcacaaaf4 ("unicode: introduce UTF-8 character database") Signed-off-by: Colin Ian King Acked-by: Gabriel Krisman Bertazi --- scripts/mkutf8data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/mkutf8data.c b/scripts/mkutf8data.c index 12ce94b43be6..0563ba679bbb 100644 --- a/scripts/mkutf8data.c +++ b/scripts/mkutf8data.c @@ -2706,7 +2706,7 @@ static utf8leaf_t *utf8hangul(const char *str, unsigned char *hangul) static utf8leaf_t *utf8nlookup(struct tree *tree, unsigned char *hangul, const char *s, size_t len) { - utf8trie_t *trie = utf8data + tree->index; + utf8trie_t *trie; int offlen; int offset; int mask; @@ -2716,6 +2716,7 @@ static utf8leaf_t *utf8nlookup(struct tree *tree, unsigned char *hangul, return NULL; if (len == 0) return NULL; + trie = utf8data + tree->index; node = 1; while (node) { offlen = (*trie & OFFLEN) >> OFFLEN_SHIFT;