From patchwork Fri Oct 14 07:57:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li zeming X-Patchwork-Id: 2565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp57197wrs; Fri, 14 Oct 2022 01:05:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wGt/gT658U1R4Bnw4koKfvcv17h8PkcbqbT0JIQCT2EYiB6Xc0Wn4yCXz8QKH1+LgGDM9 X-Received: by 2002:a50:eb81:0:b0:458:e40e:68d7 with SMTP id y1-20020a50eb81000000b00458e40e68d7mr3221137edr.131.1665734703556; Fri, 14 Oct 2022 01:05:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665734703; cv=none; d=google.com; s=arc-20160816; b=q8PWEelEPrgmjzeu/qltqaLZkTuv75h7dTumWuVpNf4xAT99F4MrJghwyqgMqc0qCx vDEXrq/7Xo4rZQRLjqnujN0wjzvGy1Mhdt95F0lHWFgSkG1nCWX31Ltxntp0LkP0rW14 +1kuveW+qf+Yo9IAmA4MEah7HSzZz2cIIYVTuGe702Lsy5TpqqI2m66UFFVsdumabMTF Gnt8iefqKnHwj75fQeJiHnoAU6XTkrkPYhyAa0EBf9DVKAu1desve4Wop0kNiwDyIF+6 ZVAOi7knoPkNfZzSdFigkLQ2L4j1OUZU3U/SM3k+z+s5O/K2VxfzEXdcmawmBxr3L+oL dnow== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m2-20020a1709062ac200b0078da856a4ecsi1548496eje.391.2022.10.14.01.04.37; Fri, 14 Oct 2022 01:05:03 -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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746649432559414307?= X-GMAIL-MSGID: =?utf-8?q?1746649432559414307?= 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; }