From: Li zeming <zeming@nfschina.com>
To: krisman@collabora.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Li zeming <zeming@nfschina.com>
Subject: [PATCH] unicode: mkutf8data: Add malloc return value detection
Date: Fri, 14 Oct 2022 15:57:10 +0800 [thread overview]
Message-ID: <20221014075710.310943-1-zeming@nfschina.com> (raw)
Add the check and judgment statement of malloc return value.
Signed-off-by: Li zeming <zeming@nfschina.com>
---
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
next reply other threads:[~2022-10-14 7:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-14 7:57 Li zeming [this message]
2022-10-14 13:03 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221014075710.310943-1-zeming@nfschina.com \
--to=zeming@nfschina.com \
--cc=krisman@collabora.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®