All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@collabora.com>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org,
	Gabriel Krisman Bertazi <krisman@collabora.com>
Subject: [PATCH e2fsprogs 03/11] ext2fs: Add method to validate casefolded strings
Date: Wed, 25 Mar 2020 17:18:03 -0400	[thread overview]
Message-ID: <20200325211812.2971787-4-krisman@collabora.com> (raw)
In-Reply-To: <20200325211812.2971787-1-krisman@collabora.com>

This is exported to be used by fsck.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.com>
---
 lib/ext2fs/ext2fs.h   |  2 ++
 lib/ext2fs/ext2fsP.h  |  2 ++
 lib/ext2fs/nls_utf8.c | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 93ecf29c568d..bf54130f4edb 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1611,6 +1611,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 ad8b7d52d77c..30564ded1e2b 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 e4c4e7a30990..f59484142e19 100644
--- a/lib/ext2fs/nls_utf8.c
+++ b/lib/ext2fs/nls_utf8.c
@@ -920,8 +920,38 @@ 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;
+	size_t		ret = 0;
+	unsigned char	hangul[UTF8HANGULLEAF];
+
+	if (!data)
+		return -1;
+	while (len && *s) {
+		leaf = utf8nlookup(data, hangul, s, len);
+		if (!leaf) {
+			*pos = s;
+			return 1;
+		}
+		if (utf8agetab[LEAF_GEN(leaf)] > data->maxage)
+			ret += utf8clen(s);
+		else if (LEAF_CCC(leaf) == DECOMPOSE)
+			ret += strlen(LEAF_STR(leaf));
+		else
+			ret += utf8clen(s);
+		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 +966,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.25.0


  parent reply	other threads:[~2020-03-25 21:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 21:18 [PATCH e2fsprogs 00/11] Improvements for Case-insensitive handling Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 01/11] tune2fs: Allow enabling casefold feature after fs creation Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 02/11] tune2fs: Fix casefold+encrypt error message Gabriel Krisman Bertazi
2020-03-25 21:18 ` Gabriel Krisman Bertazi [this message]
2020-03-25 21:18 ` [PATCH e2fsprogs 04/11] ext2fs: Implement faster CI comparison of strings Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 05/11] e2fsck: Fix entries with invalid encoded characters Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 06/11] e2fsck: Support casefold directories when rehashing Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 07/11] dict: Support comparison with context Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 08/11] e2fsck: Detect duplicated casefolded direntries for rehash Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 09/11] e2fsck: Add option to force encoded filename verification Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 10/11] e2fsck.8.in: Document check_encoding extended option Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 11/11] tests: f_bad_fname: Test fixes of invalid filenames and duplicates Gabriel Krisman Bertazi
2020-03-25 21:18 ` [PATCH e2fsprogs 11/11] tests: f_bad_fname: Validate fix " Gabriel Krisman Bertazi
2020-03-26 17:25   ` Gabriel Krisman Bertazi

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=20200325211812.2971787-4-krisman@collabora.com \
    --to=krisman@collabora.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.