Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp605881pxb; Thu, 5 Nov 2020 08:19:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI48pDBHLUNwZnucrJs5dZVIpysL+9KVRJKRvCeBT8vLgI4Gbfeb5ohoYCLP77q1n09CDg X-Received: by 2002:a17:906:4bc9:: with SMTP id x9mr2986526ejv.37.1604593163128; Thu, 05 Nov 2020 08:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604593163; cv=none; d=google.com; s=arc-20160816; b=Gef3o08vlgvfTV6lNCvZeu6VJpLxsubhIYR2zDLRzd7TerPno14FxwP+t6gMWXx6R4 t6K2N84ZBT6TZNXhrbcQhP8uGkNwcx8F0nRJHNkRq/lOsri4m0VDRlJZulaJJXlZ8OEw Dv8ulUBdJ3W1v2QUdjnVjF2Bcfo603SXwM0B5QMhpV2d27fts0jBk6O3C4jFQMCU/sKI SgVJ6Q2A1ONYCx0t9F8FBwoxB39sADQLb2ne/A2R61+oMMk5mtvGKspa/8ZUbCpFlimG tuRhIup/EqX3IWTcQY1wK0n8dlNcJ/4O/rBcluBqrmoiI7U5PqmDEDFHwCqlBeqjzi7n 6NUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=sPuvrieOsm29hksJFFYYaUBfQyM+YMjF0Z87DqkcfJU=; b=N2eOLOUPBDMlyTAgDNPDbHMR/VKWL86n6+zV9Hh7KaXjbQmFpxXrI9v6cGTncSR+ui D/YTQ2sAEWc373Y6aL/p6x0BKMM/6LjMpC/p3ziQknyTnA+NruCevnPiLWBI5Y0uQ3ZK qmPdDMAbR/9kBIVAdZ4uzsL7aJt5gDWGw/zvUfWqXX7HSnvu95EZhYKeoLk5XIR98D8A Dsk5NsQwnM2ZOUVuG2mAtjegMBz+yO7xk2qc4dw5d3ZJiijO6EkgHkJc0Nravcr35Iip iTfiKAq6T2PW3oQaiGHhlJtbj0DhGW/Nx0bzvZZ6Rp82Jsa+i+k7f1aiUAhjrqACzwiY Aegw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si1387116ejc.351.2020.11.05.08.18.59; Thu, 05 Nov 2020 08:19:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728999AbgKEQSK (ORCPT + 99 others); Thu, 5 Nov 2020 11:18:10 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:49728 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726371AbgKEQR7 (ORCPT ); Thu, 5 Nov 2020 11:17:59 -0500 Received: from xps.home (unknown [IPv6:2a01:e35:2fb5:1510:4a7e:bc14:686e:75db]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: aferraris) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5938A1F4611E; Thu, 5 Nov 2020 16:17:58 +0000 (GMT) From: Arnaud Ferraris To: linux-ext4@vger.kernel.org Cc: Gabriel Krisman Bertazi , Arnaud Ferraris Subject: [PATCH 03/11] ext2fs: Add method to validate casefolded strings Date: Thu, 5 Nov 2020 17:16:35 +0100 Message-Id: <20201105161642.87488-4-arnaud.ferraris@collabora.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201105161642.87488-1-arnaud.ferraris@collabora.com> References: <20201105161642.87488-1-arnaud.ferraris@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Gabriel Krisman Bertazi This is exported to be used by fsck. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Arnaud Ferraris --- lib/ext2fs/ext2fs.h | 2 ++ lib/ext2fs/ext2fsP.h | 2 ++ lib/ext2fs/nls_utf8.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 69c8a3ff..4065cb70 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1613,6 +1613,8 @@ extern errcode_t ext2fs_new_dir_inline_data(ext2_filsys fs, ext2_ino_t dir_ino, /* nls_utf8.c */ extern const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding); +extern int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table, + char *s, size_t len, char **pos); /* mkdir.c */ extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, diff --git a/lib/ext2fs/ext2fsP.h b/lib/ext2fs/ext2fsP.h index ad8b7d52..30564ded 100644 --- a/lib/ext2fs/ext2fsP.h +++ b/lib/ext2fs/ext2fsP.h @@ -104,6 +104,8 @@ struct ext2fs_nls_ops { int (*casefold)(const struct ext2fs_nls_table *charset, const unsigned char *str, size_t len, unsigned char *dest, size_t dlen); + int (*validate)(const struct ext2fs_nls_table *table, + char *s, size_t len, char **pos); }; /* Function prototypes */ diff --git a/lib/ext2fs/nls_utf8.c b/lib/ext2fs/nls_utf8.c index e4c4e7a3..903c65ba 100644 --- a/lib/ext2fs/nls_utf8.c +++ b/lib/ext2fs/nls_utf8.c @@ -920,8 +920,31 @@ invalid_seq: return -EINVAL; } + +static int utf8_validate(const struct ext2fs_nls_table *table, + char *s, size_t len, char **pos) +{ + const struct utf8data *data = utf8nfdicf(table->version); + utf8leaf_t *leaf; + unsigned char hangul[UTF8HANGULLEAF]; + + if (!data) + return -1; + while (len && *s) { + leaf = utf8nlookup(data, hangul, s, len); + if (!leaf) { + *pos = s; + return 1; + } + len -= utf8clen(s); + s += utf8clen(s); + } + return 0; +} + static const struct ext2fs_nls_ops utf8_ops = { .casefold = utf8_casefold, + .validate = utf8_validate, }; static const struct ext2fs_nls_table nls_utf8 = { @@ -936,3 +959,9 @@ const struct ext2fs_nls_table *ext2fs_load_nls_table(int encoding) return NULL; } + +int ext2fs_check_encoded_name(const struct ext2fs_nls_table *table, + char *name, size_t len, char **pos) +{ + return table->ops->validate(table, name, len, pos); +} -- 2.28.0