Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1455919ybe; Thu, 5 Sep 2019 16:03:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxI8xSNPHPLqaFXs6od6bWsCqKLJpLVroCSZvrhIFNFiUHTZnllZ7rMARY2vM/8MxQrGSJq X-Received: by 2002:a63:c203:: with SMTP id b3mr5416427pgd.450.1567724597846; Thu, 05 Sep 2019 16:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567724597; cv=none; d=google.com; s=arc-20160816; b=LUcc7h6vQkHa8KVeHlZh3PGFZv4WmD6JZoXR/AgBPcNWeGEFXlWUsHQK0d+J5UYgYn TzucbNpsO0YAGTPGJYT5Sc8SWMOOC//+YFolLt5yqS6yUJ5GLt+QG6LlNRxMUY8dgNgq KDSEfOHxQxC2jUhKLWnP1GPt9Y7ZxjN1r0A0Hy+/3nPktW1LbLfJ4kZlxCYR6DJXfJMn An0sDqnSMiqPoW2mduepiJeLSjnhjoEcbhlz5UTuiwU9kbaLMvaUXC1qPvdWfeCpOGyn 7vbVhz4YX9VN/9wpuKPs8PckffX/6vMuvG1rvToY6EfG6oohpym0PG9cC3J1eHJTLFRr 9uLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=YPaf/3HODheWXg9FiYkYBdQQUbljnxRoQGDUIrxmt4I=; b=suMTjAQXTUsR2gr0J7hNucoqV04AX1xhKi3pnb4+DAE9z8VGG6v+ogGUNYVo6UMpop VM0ZfBkjI3R/9O1iip4FclH8g6qDs7TmJ/hYNrnl2lS8zDmceLS7iSi9CGBgEtItLfiC 2h/d+BSh2najdZzv9QzVaQ4J4LgdikZPzg6nDXtG2nax/Hm+hsQzX3nuw4ii8wDMGXYB rOQC4Ep2T6ZicszkzLO/+IxK3oaoOrHPVLDWOW/q+ffXbTlXotMESOtG25YKNQhn6YZE t2kWGPfmOtWX6Kn4zPJuXY082PSBIlheXIDlg2fnS3F+/4VTdfr0bKVZsCLrKUHfwhzr d/Ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 44si3237797pld.418.2019.09.05.16.03.01; Thu, 05 Sep 2019 16:03:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403933AbfIETot (ORCPT + 99 others); Thu, 5 Sep 2019 15:44:49 -0400 Received: from fieldses.org ([173.255.197.46]:56752 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390054AbfIETog (ORCPT ); Thu, 5 Sep 2019 15:44:36 -0400 Received: by fieldses.org (Postfix, from userid 2815) id F03084116; Thu, 5 Sep 2019 15:44:34 -0400 (EDT) From: "J. Bruce Fields" To: Andy Shevchenko Cc: linux-kernel@vger.kernel.org, Kees Cook , "J. Bruce Fields" Subject: [PATCH 9/9] Remove string_escape_mem_ascii Date: Thu, 5 Sep 2019 15:44:33 -0400 Message-Id: <1567712673-1629-9-git-send-email-bfields@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1567712673-1629-1-git-send-email-bfields@redhat.com> References: <20190905193604.GC31247@fieldses.org> <1567712673-1629-1-git-send-email-bfields@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "J. Bruce Fields" It's easier to do this in string_escape_mem now. Might also consider non-ascii and quote-mark sprintf modifiers and then we might make do with seq_printk. --- fs/seq_file.c | 3 ++- include/linux/string_helpers.h | 3 +-- lib/string_helpers.c | 24 ++++-------------------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/fs/seq_file.c b/fs/seq_file.c index 63e5a7c4dbf7..0e45a25523ad 100644 --- a/fs/seq_file.c +++ b/fs/seq_file.c @@ -390,7 +390,8 @@ void seq_escape_mem_ascii(struct seq_file *m, const char *src, size_t isz) size_t size = seq_get_buf(m, &buf); int ret; - ret = string_escape_mem_ascii(src, isz, buf, size); + ret = string_escape_mem(src, isz, buf, size, ESCAPE_NP|ESCAPE_NONASCII| + ESCAPE_STYLE_SLASH|ESCAPE_STYLE_HEX, "\"\\"); seq_commit(m, ret < size ? ret : -1); } EXPORT_SYMBOL(seq_escape_mem_ascii); diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h index 5d350f7f6874..f3388591d83f 100644 --- a/include/linux/string_helpers.h +++ b/include/linux/string_helpers.h @@ -43,6 +43,7 @@ static inline int string_unescape_any_inplace(char *buf) #define ESCAPE_SPECIAL 0x01 #define ESCAPE_NP 0x02 +#define ESCAPE_NONASCII 0x04 #define ESCAPE_ANY_NP (ESCAPE_SPECIAL | ESCAPE_NP) #define ESCAPE_STYLE_SLASH 0x20 #define ESCAPE_STYLE_OCTAL 0x40 @@ -52,8 +53,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_str(const char *src, char *dst, size_t sz, unsigned int flags, const char *only) { diff --git a/lib/string_helpers.c b/lib/string_helpers.c index 6f553f893fda..1dacf76eada0 100644 --- a/lib/string_helpers.c +++ b/lib/string_helpers.c @@ -439,6 +439,8 @@ static bool is_special(char c) * '\a' - alert (BEL) * '\e' - escape * '\0' - null + * %ESCAPE_NONASCII: + * escape characters with the high bit set * %ESCAPE_NP: * escape only non-printable characters (checked by isprint) * %ESCAPE_ANY_NP: @@ -468,7 +470,8 @@ int string_escape_mem(const char *src, size_t isz, char *dst, size_t osz, if ((is_dict && strchr(esc, c)) || (flags & ESCAPE_NP && !isprint(c)) || - (flags & ESCAPE_SPECIAL && is_special(c))) { + (flags & ESCAPE_SPECIAL && is_special(c)) || + (flags & ESCAPE_NONASCII && !isascii(c))) { if (flags & ESCAPE_STYLE_SLASH && escape_special(c, &p, end)) @@ -491,25 +494,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. -- 2.21.0