From patchwork Tue May 4 18:08:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238397 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B527C433ED for ; Tue, 4 May 2021 18:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E71F613D2 for ; Tue, 4 May 2021 18:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232254AbhEDSJE (ORCPT ); Tue, 4 May 2021 14:09:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:5431 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbhEDSJD (ORCPT ); Tue, 4 May 2021 14:09:03 -0400 IronPort-SDR: UugYvfkfEnuJf8UctVekbv02M2DrX4NlQF079Yagzw+XqDys+VORoBkE06e6ONazsxjJkhKwuu VNDMLIFcMzew== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="185180388" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="185180388" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:06 -0700 IronPort-SDR: mLnuc8hTxKlP99dbDcGBILoO7ZjCYRobk+Dwom2LUT/SSCbkVQrHXRu4wS8gJUQkAjkd10wOAp /YD/mYqAA/Pg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="427867642" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 04 May 2021 11:08:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 98518F2; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 01/15] lib/string_helpers: Switch to use BIT() macro Date: Tue, 4 May 2021 21:08:05 +0300 Message-Id: <20210504180819.73127-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Switch to use BIT() macro for flag definitions. No changes implied. Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index fa06dcdc481e..bf01e24edd89 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -2,6 +2,7 @@ #ifndef _LINUX_STRING_HELPERS_H_ #define _LINUX_STRING_HELPERS_H_ +#include #include #include @@ -18,10 +19,10 @@ enum string_size_units { void string_get_size(u64 size, u64 blk_size, enum string_size_units units, char *buf, int len); -#define UNESCAPE_SPACE 0x01 -#define UNESCAPE_OCTAL 0x02 -#define UNESCAPE_HEX 0x04 -#define UNESCAPE_SPECIAL 0x08 +#define UNESCAPE_SPACE BIT(0) +#define UNESCAPE_OCTAL BIT(1) +#define UNESCAPE_HEX BIT(2) +#define UNESCAPE_SPECIAL BIT(3) #define UNESCAPE_ANY \ (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL) @@ -42,15 +43,15 @@ static inline int string_unescape_any_inplace(char *buf) return string_unescape_any(buf, buf, 0); } -#define ESCAPE_SPACE 0x01 -#define ESCAPE_SPECIAL 0x02 -#define ESCAPE_NULL 0x04 -#define ESCAPE_OCTAL 0x08 +#define ESCAPE_SPACE BIT(0) +#define ESCAPE_SPECIAL BIT(1) +#define ESCAPE_NULL BIT(2) +#define ESCAPE_OCTAL BIT(3) #define ESCAPE_ANY \ (ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_SPECIAL | ESCAPE_NULL) -#define ESCAPE_NP 0x10 +#define ESCAPE_NP BIT(4) #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP) -#define ESCAPE_HEX 0x20 +#define ESCAPE_HEX BIT(5) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); From patchwork Tue May 4 18:08:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238399 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DD9AC43461 for ; Tue, 4 May 2021 18:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DEBF0613E1 for ; Tue, 4 May 2021 18:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232248AbhEDSJE (ORCPT ); Tue, 4 May 2021 14:09:04 -0400 Received: from mga03.intel.com ([134.134.136.65]:4503 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232229AbhEDSJC (ORCPT ); Tue, 4 May 2021 14:09:02 -0400 IronPort-SDR: UlVdvo4/8bIs/peDSMhjG/Mdak7xZ8YPww6ISAbGqgQHdAYVHYPBPQN1LYNdm93WIlcTirnJv+ tv+ZgOWhajwQ== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="198102767" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="198102767" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:06 -0700 IronPort-SDR: WJ1BdyOd/UNVVLNYDcqO1iyYaRCtxBuURcZTePtDZu9b67Bk/0sbrYD2PGeEsAs4s3Bx2fvrKR seMPYULibfbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="539267669" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 04 May 2021 11:08:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A42F32A7; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 02/15] lib/string_helpers: Move ESCAPE_NP check inside 'else' branch in a loop Date: Tue, 4 May 2021 21:08:06 +0300 Message-Id: <20210504180819.73127-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Refactor code to have better readability by moving ESCAPE_NP handling inside 'else' branch in the loop. No functional change intended. Signed-off-by: Andy Shevchenko --- lib/string_helpers.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 7f2d5fbaf243..b10a18b4663b 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -452,10 +452,10 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * The process of escaping byte buffer includes several parts. They are applied * in the following sequence. * - * 1. The character is matched to the printable class, if asked, and in - * case of match it passes through to the output. - * 2. The character is not matched to the one from @only string and thus + * 1. The character is not matched to the one from @only string and thus * must go as-is to the output. + * 2. The character is matched to the printable class, if asked, and in + * case of match it passes through to the output. * 3. The character is checked if it falls into the class given by @flags. * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any * character. Note that they actually can't go together, otherwise @@ -506,19 +506,22 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, /* * Apply rules in the following sequence: - * - the character is printable, when @flags has - * %ESCAPE_NP bit set * - the @only string is supplied and does not contain a * character under question + * - the character is printable, when @flags has + * %ESCAPE_NP bit set * - the character doesn't fall into a class of symbols * defined by given @flags * In these cases we just pass through a character to the * output buffer. */ - if ((flags & ESCAPE_NP && isprint(c)) || - (is_dict && !strchr(only, c))) { + if (is_dict && !strchr(only, c)) { /* do nothing */ } else { + if (isprint(c) && + flags & ESCAPE_NP && escape_passthrough(c, &p, end)) + continue; + if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) continue; From patchwork Tue May 4 18:08:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F09DC4360C for ; Tue, 4 May 2021 18:08:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CE98613DB for ; Tue, 4 May 2021 18:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232302AbhEDSJU (ORCPT ); Tue, 4 May 2021 14:09:20 -0400 Received: from mga06.intel.com ([134.134.136.31]:23654 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232340AbhEDSJP (ORCPT ); Tue, 4 May 2021 14:09:15 -0400 IronPort-SDR: c6fUU7CZB4xOjZDtH/txRIu7j3hvim8iIzMnQvtiAjpYKCMQjU7EocNLA9OrRfg5nAqWY2sMU6 7WOpanFb27IA== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="259327438" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="259327438" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:06 -0700 IronPort-SDR: 6MbDAXXNIOyXh4YlcR4bicmAxwiyVfOwmJ3NMlnyfgLTG0vHrxvVOoK9RbDAd7dlhd8JpCrNnl j2MVD0AWqjnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="607105009" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 04 May 2021 11:08:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id AFA872E4; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 03/15] lib/string_helpers: Drop indentation level in string_escape_mem() Date: Tue, 4 May 2021 21:08:07 +0300 Message-Id: <20210504180819.73127-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The only one conditional is left on the upper level, move the rest to the same level and drop indentation level. No functional changes. Signed-off-by: Andy Shevchenko --- lib/string_helpers.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/string_helpers.c b/lib/string_helpers.c index b10a18b4663b..e3ef9f86cc34 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -515,29 +515,29 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, * In these cases we just pass through a character to the * output buffer. */ - if (is_dict && !strchr(only, c)) { - /* do nothing */ - } else { - if (isprint(c) && - flags & ESCAPE_NP && escape_passthrough(c, &p, end)) - continue; + if (is_dict && !strchr(only, c) && + escape_passthrough(c, &p, end)) + continue; - if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) - continue; + if (isprint(c) && + flags & ESCAPE_NP && escape_passthrough(c, &p, end)) + continue; - if (flags & ESCAPE_SPECIAL && escape_special(c, &p, end)) - continue; + if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) + continue; - if (flags & ESCAPE_NULL && escape_null(c, &p, end)) - continue; + if (flags & ESCAPE_SPECIAL && escape_special(c, &p, end)) + continue; - /* ESCAPE_OCTAL and ESCAPE_HEX always go last */ - if (flags & ESCAPE_OCTAL && escape_octal(c, &p, end)) - continue; + if (flags & ESCAPE_NULL && escape_null(c, &p, end)) + continue; - if (flags & ESCAPE_HEX && escape_hex(c, &p, end)) - continue; - } + /* ESCAPE_OCTAL and ESCAPE_HEX always go last */ + if (flags & ESCAPE_OCTAL && escape_octal(c, &p, end)) + continue; + + if (flags & ESCAPE_HEX && escape_hex(c, &p, end)) + continue; escape_passthrough(c, &p, end); } From patchwork Tue May 4 18:08:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238395 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1BCFC433B4 for ; Tue, 4 May 2021 18:08:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D36C8613D2 for ; Tue, 4 May 2021 18:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232230AbhEDSJD (ORCPT ); Tue, 4 May 2021 14:09:03 -0400 Received: from mga02.intel.com ([134.134.136.20]:5431 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232228AbhEDSJC (ORCPT ); Tue, 4 May 2021 14:09:02 -0400 IronPort-SDR: i7U+TN+TVNwqoSbaZqvQmFahruY6quvOKyeNpskK0Jrtx/DrBV/tJIOzPCmN1LA5gY1u1R0EyZ 0ZmIeIaCzbBw== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="185180390" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="185180390" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:06 -0700 IronPort-SDR: srKaqQ0k4QZ02RjMK5aEZ63MrhokB6K3OcON+NgJH60HYNcC/OMv0bAJXgfcwonRnk43aRP7Sn 3gtBcF0uCgaA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="427867644" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 04 May 2021 11:08:04 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id BB228348; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 04/15] lib/string_helpers: Introduce ESCAPE_NA for escaping non-ASCII Date: Tue, 4 May 2021 21:08:08 +0300 Message-Id: <20210504180819.73127-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Some users may want to have an ASCII based filter, provided by isascii() function. Here is the addition of a such. Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 1 + lib/string_helpers.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index bf01e24edd89..d6cf6fe10f74 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -52,6 +52,7 @@ static inline int string_unescape_any_inplace(char *buf) #define ESCAPE_NP BIT(4) #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP) #define ESCAPE_HEX BIT(5) +#define ESCAPE_NA BIT(6) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index e3ef9f86cc34..a963404b8c16 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -454,8 +454,8 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * * 1. The character is not matched to the one from @only string and thus * must go as-is to the output. - * 2. The character is matched to the printable class, if asked, and in - * case of match it passes through to the output. + * 2. The character is matched to the printable or ASCII class, if asked, + * and in case of match it passes through to the output. * 3. The character is checked if it falls into the class given by @flags. * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any * character. Note that they actually can't go together, otherwise @@ -463,7 +463,7 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * * Caller must provide valid source and destination pointers. Be aware that * destination buffer will not be NULL-terminated, thus caller have to append - * it if needs. The supported flags are:: + * it if needs. The supported flags are:: * * %ESCAPE_SPACE: (special white space, not space itself) * '\f' - form feed @@ -482,11 +482,18 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * %ESCAPE_ANY: * all previous together * %ESCAPE_NP: - * escape only non-printable characters (checked by isprint) + * escape only non-printable characters, checked by isprint() * %ESCAPE_ANY_NP: * all previous together * %ESCAPE_HEX: * '\xHH' - byte with hexadecimal value HH (2 digits) + * %ESCAPE_NA: + * escape only non-ascii characters, checked by isascii() + * + * One notable caveat, the %ESCAPE_NP and %ESCAPE_NA have higher priority + * than the rest of the flags (%ESCAPE_NP is higher than %ESCAPE_NA). + * It doesn't make much sense to use either of them without %ESCAPE_OCTAL + * or %ESCAPE_HEX, because they cover most of the other character classes. * * Return: * The total size of the escaped output that would be generated for @@ -510,6 +517,8 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, * character under question * - the character is printable, when @flags has * %ESCAPE_NP bit set + * - the character is ASCII, when @flags has + * %ESCAPE_NA bit set * - the character doesn't fall into a class of symbols * defined by given @flags * In these cases we just pass through a character to the @@ -523,6 +532,10 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, flags & ESCAPE_NP && escape_passthrough(c, &p, end)) continue; + if (isascii(c) && + flags & ESCAPE_NA && escape_passthrough(c, &p, end)) + continue; + if (flags & ESCAPE_SPACE && escape_space(c, &p, end)) continue; From patchwork Tue May 4 18:08:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D961C43600 for ; Tue, 4 May 2021 18:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 738E4613DB for ; Tue, 4 May 2021 18:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232279AbhEDSJ0 (ORCPT ); Tue, 4 May 2021 14:09:26 -0400 Received: from mga04.intel.com ([192.55.52.120]:43157 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232369AbhEDSJU (ORCPT ); Tue, 4 May 2021 14:09:20 -0400 IronPort-SDR: iblq22Th16vHjgTbCFEQWzQOXDuQVwPE4cwVBxwH4RklYNhHIm0DVbzGugZsKxyrZNecM1w7ID 1oCKTYIC9lng== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="195997142" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="195997142" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:09 -0700 IronPort-SDR: lo9M6W0jgVReKtO6JrQFQPsigrwiLS8ObJ4ML7WIchkrqwaUC6zT+T5q+fkM4XSJ10b07CtlKA sXqvP0S46Qqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="451366819" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id C69A634F; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 05/15] lib/string_helpers: Introduce ESCAPE_NAP to escape non-ASCII and non-printable Date: Tue, 4 May 2021 21:08:09 +0300 Message-Id: <20210504180819.73127-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Some users may want to have an ASCII based filter for printable only characters, provided by conjunction of isascii() and isprint() functions. Here is the addition of a such. Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 1 + lib/string_helpers.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index d6cf6fe10f74..811c6a627620 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -53,6 +53,7 @@ static inline int string_unescape_any_inplace(char *buf) #define ESCAPE_ANY_NP (ESCAPE_ANY | ESCAPE_NP) #define ESCAPE_HEX BIT(5) #define ESCAPE_NA BIT(6) +#define ESCAPE_NAP BIT(7) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index a963404b8c16..ceca5fbbd92c 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -454,9 +454,11 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * * 1. The character is not matched to the one from @only string and thus * must go as-is to the output. - * 2. The character is matched to the printable or ASCII class, if asked, + * 2. The character is matched to the printable and ASCII classes, if asked, * and in case of match it passes through to the output. - * 3. The character is checked if it falls into the class given by @flags. + * 3. The character is matched to the printable or ASCII class, if asked, + * and in case of match it passes through to the output. + * 4. The character is checked if it falls into the class given by @flags. * %ESCAPE_OCTAL and %ESCAPE_HEX are going last since they cover any * character. Note that they actually can't go together, otherwise * %ESCAPE_HEX will be ignored. @@ -489,11 +491,15 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * '\xHH' - byte with hexadecimal value HH (2 digits) * %ESCAPE_NA: * escape only non-ascii characters, checked by isascii() + * %ESCAPE_NAP: + * escape only non-printable or non-ascii characters * - * One notable caveat, the %ESCAPE_NP and %ESCAPE_NA have higher priority - * than the rest of the flags (%ESCAPE_NP is higher than %ESCAPE_NA). + * One notable caveat, the %ESCAPE_NAP, %ESCAPE_NP and %ESCAPE_NA have the + * higher priority than the rest of the flags (%ESCAPE_NAP is the highest). * It doesn't make much sense to use either of them without %ESCAPE_OCTAL * or %ESCAPE_HEX, because they cover most of the other character classes. + * %ESCAPE_NAP can utilize %ESCAPE_SPACE or %ESCAPE_SPECIAL in addition to + * the above. * * Return: * The total size of the escaped output that would be generated for @@ -515,6 +521,8 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, * Apply rules in the following sequence: * - the @only string is supplied and does not contain a * character under question + * - the character is printable and ASCII, when @flags has + * %ESCAPE_NAP bit set * - the character is printable, when @flags has * %ESCAPE_NP bit set * - the character is ASCII, when @flags has @@ -528,6 +536,10 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, escape_passthrough(c, &p, end)) continue; + if (isascii(c) && isprint(c) && + flags & ESCAPE_NAP && escape_passthrough(c, &p, end)) + continue; + if (isprint(c) && flags & ESCAPE_NP && escape_passthrough(c, &p, end)) continue; From patchwork Tue May 4 18:08:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32AF2C43460 for ; Tue, 4 May 2021 18:09:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DE10613D8 for ; Tue, 4 May 2021 18:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232250AbhEDSKp (ORCPT ); Tue, 4 May 2021 14:10:45 -0400 Received: from mga17.intel.com ([192.55.52.151]:33853 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232257AbhEDSJF (ORCPT ); Tue, 4 May 2021 14:09:05 -0400 IronPort-SDR: GVYEer7655/pPEUbop6izsKFJwYpymkMIXsu28QbR7wfvf/SmUKINSYwaeddmZEEmYqoxat72D Plzqy+rh0cRg== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="178258333" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="178258333" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:09 -0700 IronPort-SDR: IpNDWNrOXjw3wGXjKQPsaoRPPhUSyNI4EdFKeRy451rHowTnuK60ee25hrnIdtTXRayXpAHPNg 9BMJSYrSh/YA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="390052755" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D212D35E; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 06/15] lib/string_helpers: Allow to append additional characters to be escaped Date: Tue, 4 May 2021 21:08:10 +0300 Message-Id: <20210504180819.73127-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Introduce a new flag to append additional characters, passed in 'only' parameter, to be escaped if they fall in the corresponding class. Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 1 + lib/string_helpers.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 811c6a627620..f8728ed4d563 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -54,6 +54,7 @@ static inline int string_unescape_any_inplace(char *buf) #define ESCAPE_HEX BIT(5) #define ESCAPE_NA BIT(6) #define ESCAPE_NAP BIT(7) +#define ESCAPE_APPEND BIT(8) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); diff --git a/lib/string_helpers.c b/lib/string_helpers.c index ceca5fbbd92c..c15aea7a82e9 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -493,6 +493,11 @@ static bool escape_hex(unsigned char c, char **dst, char *end) * escape only non-ascii characters, checked by isascii() * %ESCAPE_NAP: * escape only non-printable or non-ascii characters + * %ESCAPE_APPEND: + * append characters from @only to be escaped by the given classes + * + * %ESCAPE_APPEND would help to pass additional characters to the escaped, when + * one of %ESCAPE_NP, %ESCAPE_NA, or %ESCAPE_NAP is provided. * * One notable caveat, the %ESCAPE_NAP, %ESCAPE_NP and %ESCAPE_NA have the * higher priority than the rest of the flags (%ESCAPE_NAP is the highest). @@ -513,9 +518,11 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, char *p = dst; char *end = p + osz; bool is_dict = only && *only; + bool is_append = flags & ESCAPE_APPEND; while (isz--) { unsigned char c = *src++; + bool in_dict = is_dict && strchr(only, c); /* * Apply rules in the following sequence: @@ -531,20 +538,24 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, * defined by given @flags * In these cases we just pass through a character to the * output buffer. + * + * When %ESCAPE_APPEND is passed, the characters from @only + * have been excluded from the %ESCAPE_NAP, %ESCAPE_NP, and + * %ESCAPE_NA cases. */ - if (is_dict && !strchr(only, c) && + if (!(is_append || in_dict) && is_dict && escape_passthrough(c, &p, end)) continue; - if (isascii(c) && isprint(c) && + if (!(is_append && in_dict) && isascii(c) && isprint(c) && flags & ESCAPE_NAP && escape_passthrough(c, &p, end)) continue; - if (isprint(c) && + if (!(is_append && in_dict) && isprint(c) && flags & ESCAPE_NP && escape_passthrough(c, &p, end)) continue; - if (isascii(c) && + if (!(is_append && in_dict) && isascii(c) && flags & ESCAPE_NA && escape_passthrough(c, &p, end)) continue; From patchwork Tue May 4 18:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7FD2C433ED for ; Tue, 4 May 2021 18:09:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C43EA613D3 for ; Tue, 4 May 2021 18:09:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232049AbhEDSKp (ORCPT ); Tue, 4 May 2021 14:10:45 -0400 Received: from mga03.intel.com ([134.134.136.65]:4503 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232262AbhEDSJF (ORCPT ); Tue, 4 May 2021 14:09:05 -0400 IronPort-SDR: a9nVJRRMEs2maSMH6CrQzR5RYa7YiAz7HBtgFdqyooCzr11WkEE/Z5VkE89PbFEHSAZoL59TLI rsfntDYpOCqQ== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="198102780" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="198102780" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:10 -0700 IronPort-SDR: V5HfvSqKutDJd67XnLWWCUmRRshC4Yg3mdNf4ZKEAlGqqQavw4TRdapbvawAkipIjPzR65yF3B k3c9W0x9dZnQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="621628453" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id DE6B5417; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 07/15] lib/test-string_helpers: Print flags in hexadecimal format Date: Tue, 4 May 2021 21:08:11 +0300 Message-Id: <20210504180819.73127-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Since flags are bitmapped, it's better to print them in hexadecimal format. Signed-off-by: Andy Shevchenko --- lib/test-string_helpers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 10360d4ea273..079fb12d59cc 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -19,7 +19,7 @@ static __init bool test_string_check_buf(const char *name, unsigned int flags, if (q_real == q_test && !memcmp(out_test, out_real, q_test)) return true; - pr_warn("Test '%s' failed: flags = %u\n", name, flags); + pr_warn("Test '%s' failed: flags = %#x\n", name, flags); print_hex_dump(KERN_WARNING, "Input: ", DUMP_PREFIX_NONE, 16, 1, in, p, true); @@ -290,7 +290,7 @@ test_string_escape_overflow(const char *in, int p, unsigned int flags, const cha q_real = string_escape_mem(in, p, NULL, 0, flags, esc); if (q_real != q_test) - pr_warn("Test '%s' failed: flags = %u, osz = 0, expected %d, got %d\n", + pr_warn("Test '%s' failed: flags = %#x, osz = 0, expected %d, got %d\n", name, flags, q_test, q_real); } From patchwork Tue May 4 18:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38EC6C433B4 for ; Tue, 4 May 2021 18:08:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE6BA61177 for ; Tue, 4 May 2021 18:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232361AbhEDSJP (ORCPT ); Tue, 4 May 2021 14:09:15 -0400 Received: from mga06.intel.com ([134.134.136.31]:23654 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232353AbhEDSJO (ORCPT ); Tue, 4 May 2021 14:09:14 -0400 IronPort-SDR: SvrfwNgfJcaTWwYhgUuTWPlLUViULPlSZOw/s1rl4qPY6rD00+jpkayZi4X4O2zCG2E8sBmnfO hD+zwoOtHPhg== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="259327453" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="259327453" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:09 -0700 IronPort-SDR: lm1jmOQnp2N6r3SL4Ml+gjPFVwU87oAQWMPL6B8s40k1uQZ6eNvcRtz1aI/YIupG0PFLbxZRue 9RJ/237k5yUg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="607105035" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id EA636461; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 08/15] lib/test-string_helpers: Get rid of trailing comma in terminators Date: Tue, 4 May 2021 21:08:12 +0300 Message-Id: <20210504180819.73127-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Terminators by definition shouldn't accept anything behind. Make them robust by removing trailing commas. Signed-off-by: Andy Shevchenko --- lib/test-string_helpers.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 079fb12d59cc..3e2def9ccfac 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -136,7 +136,7 @@ static const struct test_string_2 escape0[] __initconst = {{ .flags = ESCAPE_SPACE | ESCAPE_HEX, },{ /* terminator */ - }}, + }} },{ .in = "\\h\\\"\a\e\\", .s1 = {{ @@ -150,7 +150,7 @@ static const struct test_string_2 escape0[] __initconst = {{ .flags = ESCAPE_SPECIAL | ESCAPE_HEX, },{ /* terminator */ - }}, + }} },{ .in = "\eb \\C\007\"\x90\r]", .s1 = {{ @@ -201,7 +201,7 @@ static const struct test_string_2 escape0[] __initconst = {{ .flags = ESCAPE_NP | ESCAPE_HEX, },{ /* terminator */ - }}, + }} },{ /* terminator */ }}; @@ -217,7 +217,7 @@ static const struct test_string_2 escape1[] __initconst = {{ .flags = ESCAPE_HEX, },{ /* terminator */ - }}, + }} },{ .in = "\\h\\\"\a\e\\", .s1 = {{ @@ -225,7 +225,7 @@ static const struct test_string_2 escape1[] __initconst = {{ .flags = ESCAPE_OCTAL, },{ /* terminator */ - }}, + }} },{ .in = "\eb \\C\007\"\x90\r]", .s1 = {{ @@ -233,7 +233,7 @@ static const struct test_string_2 escape1[] __initconst = {{ .flags = ESCAPE_OCTAL, },{ /* terminator */ - }}, + }} },{ /* terminator */ }}; From patchwork Tue May 4 18:08:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8812C433ED for ; Tue, 4 May 2021 18:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB074613D2 for ; Tue, 4 May 2021 18:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232327AbhEDSJK (ORCPT ); Tue, 4 May 2021 14:09:10 -0400 Received: from mga05.intel.com ([192.55.52.43]:14965 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232263AbhEDSJG (ORCPT ); Tue, 4 May 2021 14:09:06 -0400 IronPort-SDR: QV6vj10Xlv8GBbYtTG9d4ukuDhyDLzjk16xrsnnNcvSbvz+VoOkS6TOYGvQIDJ5eIKFWuQ77A0 d2KJEeu+1Icw== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="283455810" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="283455810" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:09 -0700 IronPort-SDR: dwPp6Nmmh2Wsc+S5wToQVxaaGyzDoPY1j2AOlz9g8/9ma/EiCjf+ISXBDZzzHdkaIu8G+AuEau Ux3FYyO9D0Hg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="429171897" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 028CC61D; Tue, 4 May 2021 21:08:23 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 09/15] lib/test-string_helpers: Add test cases for new features Date: Tue, 4 May 2021 21:08:13 +0300 Message-Id: <20210504180819.73127-10-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org We have got new flags and hence new features of string_escape_mem(). Add test cases for that. Signed-off-by: Andy Shevchenko --- include/linux/string_helpers.h | 4 + lib/test-string_helpers.c | 141 +++++++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 8 deletions(-) diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index f8728ed4d563..9b0eca2badf2 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -26,6 +26,8 @@ void string_get_size(u64 size, u64 blk_size, enum string_size_units units, #define UNESCAPE_ANY \ (UNESCAPE_SPACE | UNESCAPE_OCTAL | UNESCAPE_HEX | UNESCAPE_SPECIAL) +#define UNESCAPE_ALL_MASK GENMASK(3, 0) + int string_unescape(char *src, char *dst, size_t size, unsigned int flags); static inline int string_unescape_inplace(char *buf, unsigned int flags) @@ -56,6 +58,8 @@ static inline int string_unescape_any_inplace(char *buf) #define ESCAPE_NAP BIT(7) #define ESCAPE_APPEND BIT(8) +#define ESCAPE_ALL_MASK GENMASK(8, 0) + int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); diff --git a/lib/test-string_helpers.c b/lib/test-string_helpers.c index 3e2def9ccfac..2185d71704f0 100644 --- a/lib/test-string_helpers.c +++ b/lib/test-string_helpers.c @@ -202,11 +202,25 @@ static const struct test_string_2 escape0[] __initconst = {{ },{ /* terminator */ }} +},{ + .in = "\007 \eb\"\x90\xCF\r", + .s1 = {{ + .out = "\007 \eb\"\\220\\317\r", + .flags = ESCAPE_OCTAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\\x90\\xcf\r", + .flags = ESCAPE_HEX | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_NA, + },{ + /* terminator */ + }} },{ /* terminator */ }}; -#define TEST_STRING_2_DICT_1 "b\\ \t\r" +#define TEST_STRING_2_DICT_1 "b\\ \t\r\xCF" static const struct test_string_2 escape1[] __initconst = {{ .in = "\f\\ \n\r\t\v", .s1 = {{ @@ -215,14 +229,38 @@ static const struct test_string_2 escape1[] __initconst = {{ },{ .out = "\f\\x5c\\x20\n\\x0d\\x09\v", .flags = ESCAPE_HEX, + },{ + .out = "\f\\134\\040\n\\015\\011\v", + .flags = ESCAPE_ANY | ESCAPE_APPEND, + },{ + .out = "\\014\\134\\040\\012\\015\\011\\013", + .flags = ESCAPE_OCTAL | ESCAPE_APPEND | ESCAPE_NAP, + },{ + .out = "\\x0c\\x5c\\x20\\x0a\\x0d\\x09\\x0b", + .flags = ESCAPE_HEX | ESCAPE_APPEND | ESCAPE_NAP, + },{ + .out = "\f\\134\\040\n\\015\\011\v", + .flags = ESCAPE_OCTAL | ESCAPE_APPEND | ESCAPE_NA, + },{ + .out = "\f\\x5c\\x20\n\\x0d\\x09\v", + .flags = ESCAPE_HEX | ESCAPE_APPEND | ESCAPE_NA, },{ /* terminator */ }} },{ - .in = "\\h\\\"\a\e\\", + .in = "\\h\\\"\a\xCF\e\\", .s1 = {{ - .out = "\\134h\\134\"\a\e\\134", + .out = "\\134h\\134\"\a\\317\e\\134", .flags = ESCAPE_OCTAL, + },{ + .out = "\\134h\\134\"\a\\317\e\\134", + .flags = ESCAPE_ANY | ESCAPE_APPEND, + },{ + .out = "\\134h\\134\"\\007\\317\\033\\134", + .flags = ESCAPE_OCTAL | ESCAPE_APPEND | ESCAPE_NAP, + },{ + .out = "\\134h\\134\"\a\\317\e\\134", + .flags = ESCAPE_OCTAL | ESCAPE_APPEND | ESCAPE_NA, },{ /* terminator */ }} @@ -234,6 +272,88 @@ static const struct test_string_2 escape1[] __initconst = {{ },{ /* terminator */ }} +},{ + .in = "\007 \eb\"\x90\xCF\r", + .s1 = {{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_SPACE | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_SPECIAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\317\r", + .flags = ESCAPE_OCTAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\317\r", + .flags = ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\317\r", + .flags = ESCAPE_SPECIAL | ESCAPE_OCTAL | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\317\r", + .flags = ESCAPE_ANY | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\xcf\r", + .flags = ESCAPE_HEX | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\xcf\r", + .flags = ESCAPE_SPACE | ESCAPE_HEX | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\xcf\r", + .flags = ESCAPE_SPECIAL | ESCAPE_HEX | ESCAPE_NA, + },{ + .out = "\007 \eb\"\x90\\xcf\r", + .flags = ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_HEX | ESCAPE_NA, + },{ + /* terminator */ + }} +},{ + .in = "\007 \eb\"\x90\xCF\r", + .s1 = {{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\xCF\\r", + .flags = ESCAPE_SPACE | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\xCF\r", + .flags = ESCAPE_SPECIAL | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\xCF\\r", + .flags = ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\317\\015", + .flags = ESCAPE_OCTAL | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\317\\r", + .flags = ESCAPE_SPACE | ESCAPE_OCTAL | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\317\\015", + .flags = ESCAPE_SPECIAL | ESCAPE_OCTAL | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\317\r", + .flags = ESCAPE_ANY | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\xcf\\x0d", + .flags = ESCAPE_HEX | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\xcf\\r", + .flags = ESCAPE_SPACE | ESCAPE_HEX | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\xcf\\x0d", + .flags = ESCAPE_SPECIAL | ESCAPE_HEX | ESCAPE_NAP, + },{ + .out = "\007 \eb\"\x90\\xcf\\r", + .flags = ESCAPE_SPACE | ESCAPE_SPECIAL | ESCAPE_HEX | ESCAPE_NAP, + },{ + /* terminator */ + }} },{ /* terminator */ }}; @@ -315,8 +435,13 @@ static __init void test_string_escape(const char *name, /* NULL injection */ if (flags & ESCAPE_NULL) { in[p++] = '\0'; - out_test[q_test++] = '\\'; - out_test[q_test++] = '0'; + /* '\0' passes isascii() test */ + if (flags & ESCAPE_NA && !(flags & ESCAPE_APPEND && esc)) { + out_test[q_test++] = '\0'; + } else { + out_test[q_test++] = '\\'; + out_test[q_test++] = '0'; + } } /* Don't try strings that have no output */ @@ -459,17 +584,17 @@ static int __init test_string_helpers_init(void) unsigned int i; pr_info("Running tests...\n"); - for (i = 0; i < UNESCAPE_ANY + 1; i++) + for (i = 0; i < UNESCAPE_ALL_MASK + 1; i++) test_string_unescape("unescape", i, false); test_string_unescape("unescape inplace", get_random_int() % (UNESCAPE_ANY + 1), true); /* Without dictionary */ - for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) + for (i = 0; i < ESCAPE_ALL_MASK + 1; i++) test_string_escape("escape 0", escape0, i, TEST_STRING_2_DICT_0); /* With dictionary */ - for (i = 0; i < (ESCAPE_ANY_NP | ESCAPE_HEX) + 1; i++) + for (i = 0; i < ESCAPE_ALL_MASK + 1; i++) test_string_escape("escape 1", escape1, i, TEST_STRING_2_DICT_1); /* Test string_get_size() */ From patchwork Tue May 4 18:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C21BEC43617 for ; Tue, 4 May 2021 18:08:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8F6E61177 for ; Tue, 4 May 2021 18:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232351AbhEDSJN (ORCPT ); Tue, 4 May 2021 14:09:13 -0400 Received: from mga07.intel.com ([134.134.136.100]:41081 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbhEDSJG (ORCPT ); Tue, 4 May 2021 14:09:06 -0400 IronPort-SDR: xt4R20iKklfn+UN88ubuUX3TkOtz1VjODboRKDSFH55jdh7QPue4W53AzAh9iRv6asPdKifc1A WNSj4kua+F/Q== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="261993802" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="261993802" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:11 -0700 IronPort-SDR: DvOmjqsFX3DiL+jZvB6kmSBzISvZE+VtSnslgISxcDhuFmYjqSA3jCEK7r7IufzlrGUk9PEgen 4jc36wd6d4ag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="458141116" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0E595934; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 10/15] MAINTAINERS: Add myself as designated reviewer for generic string library Date: Tue, 4 May 2021 21:08:14 +0300 Message-Id: <20210504180819.73127-11-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Add myself as designated reviewer for generic string library. Signed-off-by: Andy Shevchenko --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 1783372a608a..2c5797fc462c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7650,6 +7650,14 @@ L: linux-input@vger.kernel.org S: Maintained F: drivers/input/touchscreen/resistive-adc-touch.c +GENERIC STRING LIBRARY +R: Andy Shevchenko +S: Maintained +F: lib/string.c +F: lib/string_helpers.c +F: lib/test_string.c +F: lib/test-string_helpers.c + GENERIC UIO DRIVER FOR PCI DEVICES M: "Michael S. Tsirkin" L: kvm@vger.kernel.org From patchwork Tue May 4 18:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7843C43616 for ; Tue, 4 May 2021 18:08:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FAD6613DB for ; Tue, 4 May 2021 18:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232312AbhEDSJJ (ORCPT ); Tue, 4 May 2021 14:09:09 -0400 Received: from mga01.intel.com ([192.55.52.88]:28420 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbhEDSJG (ORCPT ); Tue, 4 May 2021 14:09:06 -0400 IronPort-SDR: fm3jybSWohfVVDpvhBA+f1akfGYg57wQraqGEWUqYa5HnKsdJYS/ne8cXUWeKymMHLfA9z03ao RCnK/9iegIhQ== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="218864648" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="218864648" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:09 -0700 IronPort-SDR: CuN3mk7g592TEkv5mnDdkSFQ7/9Yjm8bcg2KC+zYpzsQMgg2WqvZVKNDEabM8dykdsM5tRBnN8 /PilxZRWDtpw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="531265726" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1A2F79A1; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 11/15] seq_file: Introduce seq_escape_mem() Date: Tue, 4 May 2021 21:08:15 +0300 Message-Id: <20210504180819.73127-12-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Introduce seq_escape_mem() to allow users to pass additional parameters to string_escape_mem(). Suggested-by: Al Viro Signed-off-by: Andy Shevchenko --- fs/seq_file.c | 25 +++++++++++++++++++++++++ include/linux/seq_file.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/fs/seq_file.c b/fs/seq_file.c index 5059248f2d64..532cac2eae0f 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -355,6 +355,31 @@ int seq_release(struct inode *inode, struct file *file) } EXPORT_SYMBOL(seq_release); +/** + * seq_escape_mem - print data into buffer, escaping some characters + * @m: target buffer + * @src: source buffer + * @len: size of source buffer + * @flags: flags to pass to string_escape_mem() + * @esc: set of characters that need escaping + * + * Puts data into buffer, replacing each occurrence of character from + * given class (defined by @flags and @esc) with printable escaped sequence. + * + * Use seq_has_overflowed() to check for errors. + */ +void seq_escape_mem(struct seq_file *m, const char *src, size_t len, + unsigned int flags, const char *esc) +{ + char *buf; + size_t size = seq_get_buf(m, &buf); + int ret; + + ret = string_escape_mem(src, len, buf, size, flags, esc); + seq_commit(m, ret < size ? ret : -1); +} +EXPORT_SYMBOL(seq_escape_mem); + /** * seq_escape - print string into buffer, escaping some characters * @m: target buffer diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 723b1fa1177e..6de442182784 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -126,6 +126,8 @@ void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num void seq_put_hex_ll(struct seq_file *m, const char *delimiter, unsigned long long v, unsigned int width); +void seq_escape_mem(struct seq_file *m, const char *src, size_t len, + unsigned int flags, const char *esc); void seq_escape(struct seq_file *m, const char *s, const char *esc); void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz); From patchwork Tue May 4 18:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238425 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 916DBC43600 for ; Tue, 4 May 2021 18:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 722DA613F6 for ; Tue, 4 May 2021 18:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232286AbhEDSKq (ORCPT ); Tue, 4 May 2021 14:10:46 -0400 Received: from mga03.intel.com ([134.134.136.65]:4512 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbhEDSJG (ORCPT ); Tue, 4 May 2021 14:09:06 -0400 IronPort-SDR: DLKSIfnjA28kP/9JLP3S4RiEmZgqpFtxbk8kLwtTuJ98gdr2kHddsvU+E7xZYO0ObQQo9jRMEr muNBb8WxJxsw== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="198102793" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="198102793" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:11 -0700 IronPort-SDR: JNFpGkilIQ16ds4+KDGVzPEhaSbBgzpRaPHchsRrldhf1fNEBRVRKrVtpiZJbi65Rq3pVRJHFK +qrka7NrIlxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="618574585" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 04 May 2021 11:08:07 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 259529EB; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 12/15] seq_file: Add seq_escape_str() as replica of string_escape_str() Date: Tue, 4 May 2021 21:08:16 +0300 Message-Id: <20210504180819.73127-13-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In some cases we want to escape characters from NULL-terminated strings. Add seq_escape_str() as replica of string_escape_str() for that. Signed-off-by: Andy Shevchenko --- include/linux/seq_file.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 6de442182784..63f021cb1b12 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -128,6 +128,13 @@ void seq_put_hex_ll(struct seq_file *m, const char *delimiter, void seq_escape_mem(struct seq_file *m, const char *src, size_t len, unsigned int flags, const char *esc); + +static inline void seq_escape_str(struct seq_file *m, const char *src, + unsigned int flags, const char *esc) +{ + seq_escape_mem(m, src, strlen(src), flags, esc); +} + void seq_escape(struct seq_file *m, const char *s, const char *esc); void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz); From patchwork Tue May 4 18:08:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45313C43462 for ; Tue, 4 May 2021 18:08:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2251B613D2 for ; Tue, 4 May 2021 18:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232335AbhEDSJM (ORCPT ); Tue, 4 May 2021 14:09:12 -0400 Received: from mga07.intel.com ([134.134.136.100]:41081 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232296AbhEDSJH (ORCPT ); Tue, 4 May 2021 14:09:07 -0400 IronPort-SDR: 7gsjRJ41jfpITRFnOQox4Rgx6k66lEev+zxbrEza+IalF0XXzWoZB7H4mbgDpcAXGO7J2JLrV4 8/YdXgNHHLmw== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="261993809" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="261993809" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:11 -0700 IronPort-SDR: PQOMb/9wLk+RMgypUdybc+z8/u++MCkNQYwFCu20hVNz/5+FbuIgq3z5eGEEQchCh+FTvOZ28l 2vCHiang+sHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="463341899" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 04 May 2021 11:08:08 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2EBC89FA; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 13/15] seq_file: Convert seq_escape() to use seq_escape_str() Date: Tue, 4 May 2021 21:08:17 +0300 Message-Id: <20210504180819.73127-14-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Convert seq_escape() to use seq_escape_str() rather than open coding it. Note, for now we leave it as an exported symbol due to some old code that can't tolerate ctype.h being (indirectly) included. Signed-off-by: Andy Shevchenko --- fs/seq_file.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 532cac2eae0f..08f54029c2b1 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -392,12 +392,7 @@ EXPORT_SYMBOL(seq_escape_mem); */ void seq_escape(struct seq_file *m, const char *s, const char *esc) { - char *buf; - size_t size = seq_get_buf(m, &buf); - int ret; - - ret = string_escape_str(s, buf, size, ESCAPE_OCTAL, esc); - seq_commit(m, ret < size ? ret : -1); + seq_escape_str(m, s, ESCAPE_OCTAL, esc); } EXPORT_SYMBOL(seq_escape); From patchwork Tue May 4 18:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63324C433B4 for ; Tue, 4 May 2021 18:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41D2A61177 for ; Tue, 4 May 2021 18:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbhEDSJJ (ORCPT ); Tue, 4 May 2021 14:09:09 -0400 Received: from mga03.intel.com ([134.134.136.65]:4503 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbhEDSJG (ORCPT ); Tue, 4 May 2021 14:09:06 -0400 IronPort-SDR: zpOihsyrWo3MCdhbJr3xH8kkMUVJsh+gX0bXIfcwFd8G9zMrI4aOoalVuVQr0eXtAH+MTdj8eM hEFwiI32Nv/w== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="198102786" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="198102786" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:10 -0700 IronPort-SDR: tV6c1J8jOO09UiO212iYCFlXnUv8Zfdkt9vVVSuIJiOxO30kZVlYeZ8ziy3iZg3P3Ozx9pEOwY Klb8aY9BDT/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="539267692" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 04 May 2021 11:08:08 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 375F3AFA; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 14/15] nfsd: Avoid non-flexible API in seq_quote_mem() Date: Tue, 4 May 2021 21:08:18 +0300 Message-Id: <20210504180819.73127-15-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org The seq_escape_mem_ascii() is completely non-flexible and shouldn't be used. Replace it with properly called seq_escape_mem(). Signed-off-by: Andy Shevchenko --- fs/nfsd/nfs4state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b517a8794400..cd5eac2ba054 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -2351,7 +2351,7 @@ static struct nfs4_client *get_nfsdfs_clp(struct inode *inode) static void seq_quote_mem(struct seq_file *m, char *data, int len) { seq_printf(m, "\""); - seq_escape_mem_ascii(m, data, len); + seq_escape_mem(m, data, len, ESCAPE_HEX | ESCAPE_NAP | ESCAPE_APPEND, "\"\\"); seq_printf(m, "\""); } From patchwork Tue May 4 18:08:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12238411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6779C43611 for ; Tue, 4 May 2021 18:08:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CAC3613D2 for ; Tue, 4 May 2021 18:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbhEDSJK (ORCPT ); Tue, 4 May 2021 14:09:10 -0400 Received: from mga05.intel.com ([192.55.52.43]:14965 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232300AbhEDSJH (ORCPT ); Tue, 4 May 2021 14:09:07 -0400 IronPort-SDR: sbR0/Xj5BlLDjpw+GxmWHfaX2WOnyfRF/O66V3A/ESP5/Ab/SCb0eviFbpbwqXzO6mvMHb8XJd GPEeIrEh32mw== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="283455832" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="283455832" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 11:08:12 -0700 IronPort-SDR: bHWqNaW2wHK/e5DUq3qTQ0GiaiF9DlvG2lxJV43GklWABiYXMAQgxVlyVRaw6zMcvz3a8A6SwG 2vdzXd8WJ1Zw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="429171916" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 04 May 2021 11:08:10 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3FEF2B08; Tue, 4 May 2021 21:08:24 +0300 (EEST) From: Andy Shevchenko To: "J. Bruce Fields" , Andy Shevchenko , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "J. Bruce Fields" , Chuck Lever , Alexander Viro , Andy Shevchenko , Andrew Morton Subject: [PATCH v3 15/15] seq_file: Drop unused *_escape_mem_ascii() Date: Tue, 4 May 2021 21:08:19 +0300 Message-Id: <20210504180819.73127-16-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> References: <20210504180819.73127-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org There are no more users of the seq_escape_mem_ascii() followed by string_escape_mem_ascii(). Remove them for good. Signed-off-by: Andy Shevchenko --- fs/seq_file.c | 11 ----------- include/linux/seq_file.h | 1 - include/linux/string_helpers.h | 3 --- lib/string_helpers.c | 19 ------------------- 4 files changed, 34 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 08f54029c2b1..b117b212ef28 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -396,17 +396,6 @@ void seq_escape(struct seq_file *m, const char *s, const char *esc) } EXPORT_SYMBOL(seq_escape); -void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz) -{ - char *buf; - size_t size = seq_get_buf(m, &buf); - int ret; - - ret = string_escape_mem_ascii(src, isz, buf, size); - seq_commit(m, ret < size ? ret : -1); -} -EXPORT_SYMBOL(seq_escape_mem_ascii); - void seq_vprintf(struct seq_file *m, const char *f, va_list args) { int len; diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h index 63f021cb1b12..dd99569595fd 100644 --- a/include/linux/seq_file.h +++ b/include/linux/seq_file.h @@ -136,7 +136,6 @@ static inline void seq_escape_str(struct seq_file *m, const char *src, } void seq_escape(struct seq_file *m, const char *s, const char *esc); -void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz); void seq_hex_dump(struct seq_file *m, const char *prefix_str, int prefix_type, int rowsize, int groupsize, const void *buf, size_t len, diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 9b0eca2badf2..68189c4a2eb1 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -63,9 +63,6 @@ static inline int string_unescape_any_inplace(char *buf) int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, unsigned int flags, const char *only); -int string_escape_mem_ascii(const char *src, size_t isz, char *dst, - size_t osz); - static inline int string_escape_mem_any_np(const char *src, size_t isz, char *dst, size_t osz, const char *only) { diff --git a/lib/string_helpers.c b/lib/string_helpers.c index c15aea7a82e9..5a35c7e16e96 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -582,25 +582,6 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, } EXPORT_SYMBOL(string_escape_mem); -int string_escape_mem_ascii(const char *src, size_t isz, char *dst, - size_t osz) -{ - char *p = dst; - char *end = p + osz; - - while (isz--) { - unsigned char c = *src++; - - if (!isprint(c) || !isascii(c) || c == '"' || c == '\\') - escape_hex(c, &p, end); - else - escape_passthrough(c, &p, end); - } - - return p - dst; -} -EXPORT_SYMBOL(string_escape_mem_ascii); - /* * Return an allocated string that has been escaped of special characters * and double quotes, making it safe to log in quotes.