From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1] seq_file: convert mangle_path() to use string_escape_str()
Date: Wed, 9 Jan 2019 17:40:22 +0200 [thread overview]
Message-ID: <20190109154022.23551-1-andriy.shevchenko@linux.intel.com> (raw)
Since string_escape_str() does not support overlapping buffer first we check if
there is enough room in the buffer and then update a path. The side effect of
this change is in case of failure the buffer is left unchanged.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
fs/seq_file.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1dea7a8a5255..b818b23070e6 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -421,21 +421,13 @@ EXPORT_SYMBOL(seq_printf);
*/
char *mangle_path(char *s, const char *p, const char *esc)
{
- while (s <= p) {
- char c = *p++;
- if (!c) {
- return s;
- } else if (!strchr(esc, c)) {
- *s++ = c;
- } else if (s + 4 > p) {
- break;
- } else {
- *s++ = '\\';
- *s++ = '0' + ((c & 0300) >> 6);
- *s++ = '0' + ((c & 070) >> 3);
- *s++ = '0' + (c & 07);
- }
- }
+ size_t len = p + strlen(p) - s;
+ int ret;
+
+ ret = string_escape_str(p, NULL, 0, ESCAPE_OCTAL, esc);
+ if (ret < len)
+ return s + string_escape_str(p, s, len, ESCAPE_OCTAL, esc);
+
return NULL;
}
EXPORT_SYMBOL(mangle_path);
--
2.20.1
next reply other threads:[~2019-01-09 15:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-09 15:40 Andy Shevchenko [this message]
2019-01-09 18:04 ` [PATCH v1] seq_file: convert mangle_path() to use string_escape_str() Andrew Morton
2019-01-10 0:19 ` Andy Shevchenko
2019-01-10 0:19 ` Andy Shevchenko
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=20190109154022.23551-1-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).