Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1030813ybb; Wed, 25 Mar 2020 14:18:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsPPRIv47JoqKl1PNY+a/op1JCWOdeNh1Svn05VrTD384NoYmLak8phdzHMunRLPqzHFEJV X-Received: by 2002:aca:f254:: with SMTP id q81mr2659054oih.12.1585171128787; Wed, 25 Mar 2020 14:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585171128; cv=none; d=google.com; s=arc-20160816; b=kM0qlrJ7Whd0Ceu2hXX8Q6S6HxyRTfedohg8U17OilEKaL/1kVfUikUoA3C6pw0Py9 /+mafydlujdR8swB9yE/ir7YDmzc+r+jJmP+/W7CkdMgA+a66R91Z6THx33vN5WwyYIZ cOFvm3l143MNiNItlgx/zD5tTGHiv4TRFCZKdQ5uP+Or+ZAA+mV9wCYwEX0Hm3VVi1N+ Fals9y9NHZmrdqglQT7skpUosujv+ez6LWLoMZbN7gbDeWz0brX0dVybZa6+yGMO4iSF kWaGD8A3GkYmTAetTEDeHxuWhTEZUeHX2PjQY3GioaJ8wlUzYdpcsIDKf6SXdOfExrmt 7B/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=NBj/VDnZqs1Bywy7v0vHG+ZVmN6AxsCd6GIBiabAw3I=; b=D+3SpTJ2hPmpjgsUXLeubUvrl2pn88O38f69yt5AsppaPPGdspOFjwZRUarr/G89yh YM4U08pVlW1e9/wYwfClZn3aA2zK90McYuX7XCNgINPNHqByPRS/W79ASVwMtvqCx4Z+ 4yfIWXdoCc69x/TQiCoPBPRsWPhhtMDmWlrnp/F5Q53R0eytSkBR//a9/SYxjtBukMGD +HgqG9eKYXjVZMnRF9TmX3+YSmBDtufVL6c7+N6DM4gUTNHB6X0gTa0/C7GEJCJyS3Nz 9KLaj7J3h/P9EKY3qbgPpdbdm8HHEl3ipe/gapx23eUoglvOUAaSY4Yhwd+1YKbQL+TT mN6Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id v11si109559otj.299.2020.03.25.14.18.36; Wed, 25 Mar 2020 14:18:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 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 S1727386AbgCYVSc (ORCPT + 99 others); Wed, 25 Mar 2020 17:18:32 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39566 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbgCYVSb (ORCPT ); Wed, 25 Mar 2020 17:18:31 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 42AEC28666B From: Gabriel Krisman Bertazi To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH e2fsprogs 03/11] ext2fs: Add method to validate casefolded strings Date: Wed, 25 Mar 2020 17:18:03 -0400 Message-Id: <20200325211812.2971787-4-krisman@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200325211812.2971787-1-krisman@collabora.com> References: <20200325211812.2971787-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This is exported to be used by fsck. Signed-off-by: Gabriel Krisman Bertazi --- 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