From: Gabriel Krisman Bertazi Date: Sun, 28 Apr 2019 19:10:21 +0000 (-0400) Subject: ext2fs: fix potential null dereference in utf8nlookup X-Git-Tag: v1.45.1-rc1~24 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=dea1e527ebfa689ed0a0a6bc78a4f640c1fe192e;p=tools%2Fe2fsprogs.git ext2fs: fix potential null dereference in utf8nlookup Delay the access of data->offset until after the null check. This was reported by 0-day on the kernel version of the script. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/nls_utf8-norm.c b/lib/ext2fs/nls_utf8-norm.c index 5a91573..98c6700 100644 --- a/lib/ext2fs/nls_utf8-norm.c +++ b/lib/ext2fs/nls_utf8-norm.c @@ -335,7 +335,7 @@ utf8hangul(const char *str, unsigned char *hangul) static utf8leaf_t *utf8nlookup(const struct utf8data *data, unsigned char *hangul, const char *s, size_t len) { - utf8trie_t *trie = utf8data + data->offset; + utf8trie_t *trie; int offlen; int offset; int mask; @@ -345,6 +345,8 @@ static utf8leaf_t *utf8nlookup(const struct utf8data *data, return NULL; if (len == 0) return NULL; + + trie = utf8data + data->offset; node = 1; while (node) { offlen = (*trie & OFFLEN) >> OFFLEN_SHIFT;