Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp284126rwi; Fri, 14 Oct 2022 01:48:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5OkOv8okcDd1/NgXE3zjht93MLxtoBk9gYFaRBza7qMfyBhV2iSCY/2Cy1sHYn1Pn5pzhU X-Received: by 2002:a05:6402:3408:b0:43c:2dd3:d86b with SMTP id k8-20020a056402340800b0043c2dd3d86bmr3379760edc.108.1665737283017; Fri, 14 Oct 2022 01:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665737283; cv=none; d=google.com; s=arc-20160816; b=yhyuHZjVeq0JU1d+3XZSUQMEiM+aErkptQqFMFyiMQnf6M+f0G2v2OknrH+h2QL/HY QO1BJA66gbwB0AJOSFfsbFvxR/s9ZJtzNxUZvxUkOfahQMDcaazyNBy90BBaVBDdQlmz kH2PDe3vrKV0p7AYV5fdSh2898239TDyacozpx2/fbpqXm84UJQ9RBFWMoQnxM4fWEMj o2KcojVlwCudNOovQBSHoHaEKKQBFrMoW9awqxdLqwCjlWi3K1n6Hnax7l/ufYjipFWo jg7SdKi2zFBR4pKC/osF57JZYLvDapFUbmgcs/xNtFXN9tRVKIACoSrg93bet9Mua/5A VtKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=5aZgiznvJrBgNPRE0lHE86DPzNjPJP/hlFjlgtTVNvY=; b=fam1NUnhaSKiEQX6DW1XwlT8TBWPyRja6fkKiCeIG3jFekrVh4vurEdnS/OM5EipR1 NkmzeLPflT3whhZGBM83OnEzBBp4iVymGzAT9QjY4zBr5LK2UxTbbCxINybW42IltQ0Y buL3Yp80z0f+L21mGm50NqWZavHqLiLemd4Fibt4Tch9nOP6XZ53QTb6o7opMhqYHDRo WdvdHkUG2TtQk49VABXHQ081ZzKZxqR7WnEdC2yR0a81+MOIAG6QSHP5GBEhU+NnFHMR K7efZB2iJ0aBZ6OqaugI2RZk0h+d0sEf+dx5rwqQHhgfLgPbIDwgmhsgomc/NSp78VIq HIHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb4-20020a1709077e8400b0078b85fdf4e4si2037634ejc.532.2022.10.14.01.47.37; Fri, 14 Oct 2022 01:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbiJNH5Y (ORCPT + 99 others); Fri, 14 Oct 2022 03:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229970AbiJNH5R (ORCPT ); Fri, 14 Oct 2022 03:57:17 -0400 Received: from mail.nfschina.com (mail.nfschina.com [124.16.136.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 597111B94F5; Fri, 14 Oct 2022 00:57:16 -0700 (PDT) Received: from localhost (unknown [127.0.0.1]) by mail.nfschina.com (Postfix) with ESMTP id 2F4F71E80D90; Fri, 14 Oct 2022 15:57:09 +0800 (CST) X-Virus-Scanned: amavisd-new at test.com Received: from mail.nfschina.com ([127.0.0.1]) by localhost (mail.nfschina.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N3Taxyhs6Dc4; Fri, 14 Oct 2022 15:57:06 +0800 (CST) Received: from localhost.localdomain (unknown [219.141.250.2]) (Authenticated sender: zeming@nfschina.com) by mail.nfschina.com (Postfix) with ESMTPA id 348131E80D6E; Fri, 14 Oct 2022 15:57:06 +0800 (CST) From: Li zeming To: krisman@collabora.com Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Li zeming Subject: [PATCH] unicode: mkutf8data: Add malloc return value detection Date: Fri, 14 Oct 2022 15:57:10 +0800 Message-Id: <20221014075710.310943-1-zeming@nfschina.com> X-Mailer: git-send-email 2.18.2 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the check and judgment statement of malloc return value. Signed-off-by: Li zeming --- fs/unicode/mkutf8data.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c index bc1a7c8b5c8d..d7f7f7c4cf56 100644 --- a/fs/unicode/mkutf8data.c +++ b/fs/unicode/mkutf8data.c @@ -495,6 +495,9 @@ static struct node *alloc_node(struct node *parent) int bitnum; node = malloc(sizeof(*node)); + if (unlikely(!node)) + return NULL; + node->left = node->right = NULL; node->parent = parent; node->leftnode = NODE; @@ -2160,6 +2163,9 @@ static void nfdi_init(void) mapping[i++] = 0; um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdi = um; @@ -2216,6 +2222,9 @@ static void nfdicf_init(void) mapping[i++] = 0; um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdicf = um; @@ -2257,10 +2266,16 @@ static void ignore_init(void) for (unichar = first; unichar <= last; unichar++) { free(unicode_data[unichar].utf32nfdi); um = malloc(sizeof(unsigned int)); + if (unlikely(!um)) + return; + *um = 0; unicode_data[unichar].utf32nfdi = um; free(unicode_data[unichar].utf32nfdicf); um = malloc(sizeof(unsigned int)); + if (unlikely(!um)) + return; + *um = 0; unicode_data[unichar].utf32nfdicf = um; count++; @@ -2278,10 +2293,16 @@ static void ignore_init(void) line_fail(prop_name, line); free(unicode_data[unichar].utf32nfdi); um = malloc(sizeof(unsigned int)); + if (unlikely(!um)) + return; + *um = 0; unicode_data[unichar].utf32nfdi = um; free(unicode_data[unichar].utf32nfdicf); um = malloc(sizeof(unsigned int)); + if (unlikely(!um)) + return; + *um = 0; unicode_data[unichar].utf32nfdicf = um; if (verbose > 1) @@ -2360,6 +2381,9 @@ static void corrections_init(void) mapping[i++] = 0; um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); corrections[count].utf32nfdi = um; @@ -2460,11 +2484,17 @@ static void hangul_decompose(void) assert(!unicode_data[unichar].utf32nfdi); um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdi = um; assert(!unicode_data[unichar].utf32nfdicf); um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdicf = um; @@ -2474,6 +2504,9 @@ static void hangul_decompose(void) * trie. */ unicode_data[unichar].utf8nfdi = malloc(2); + if (unlikely(!(unicode_data[unichar].utf8nfdi))) + return; + unicode_data[unichar].utf8nfdi[0] = HANGUL; unicode_data[unichar].utf8nfdi[1] = '\0'; @@ -2524,12 +2557,18 @@ static void nfdi_decompose(void) break; free(unicode_data[unichar].utf32nfdi); um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdi = um; } /* Add this decomposition to nfdicf if there is no entry. */ if (!unicode_data[unichar].utf32nfdicf) { um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdicf = um; } @@ -2578,6 +2617,9 @@ static void nfdicf_decompose(void) break; free(unicode_data[unichar].utf32nfdicf); um = malloc(i * sizeof(unsigned int)); + if (unlikely(!um)) + return; + memcpy(um, mapping, i * sizeof(unsigned int)); unicode_data[unichar].utf32nfdicf = um; } -- 2.18.2