From: Thiago Rafael Becker <trbecker@gmail.com>
To: linux-cifs@vger.kernel.org
Cc: Steve French <sfrench@samba.org>,
linux-kernel@vger.kernel.org, lsahlber@redhat.com,
Thiago Rafael Becker <trbecker@gmail.com>
Subject: [PATCH 1/1] cifs: sanitize multiple delimiters in prepath
Date: Wed, 15 Dec 2021 00:08:31 -0300 [thread overview]
Message-ID: <20211215030831.24058-1-trbecker@gmail.com> (raw)
mount.cifs can pass a device with multiple delimiters in it. This will
cause rename(2) to fail with ENOENT.
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=2031200
Signed-off-by: Thiago Rafael Becker <trbecker@gmail.com>
---
fs/cifs/fs_context.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
index 6a179ae753c1..4ce8a7df3a02 100644
--- a/fs/cifs/fs_context.c
+++ b/fs/cifs/fs_context.c
@@ -434,6 +434,34 @@ int smb3_parse_opt(const char *options, const char *key, char **val)
return rc;
}
+/*
+ * remove duplicate path delimiters. Windows is supposed to do that
+ * but there are some bugs that prevent rename from working if there are
+ * multiple delimiters.
+ */
+void sanitize_path(char *path) {
+ char *pos = path, last = *path;
+ unsigned int offset = 0;
+
+ while(*(++pos)) {
+ if ((*pos == '/' || *pos == '\\') && (last == '/' || last == '\\')) {
+ offset++;
+ continue;
+ }
+
+ last = *pos;
+ *(pos - offset) = *pos;
+ }
+
+ pos = pos - offset - 1;
+
+ /* At this point, there should be only zero or one delimiter at the end of the string */
+ if (*pos != '/' && *pos != '\\')
+ pos++;
+
+ *pos = '\0';
+}
+
/*
* Parse a devname into substrings and populate the ctx->UNC and ctx->prepath
* fields with the result. Returns 0 on success and an error otherwise
@@ -497,6 +525,8 @@ smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx)
if (!ctx->prepath)
return -ENOMEM;
+ sanitize_path(ctx->prepath);
+
return 0;
}
--
2.31.1
next reply other threads:[~2021-12-15 3:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 3:08 Thiago Rafael Becker [this message]
2021-12-15 6:59 ` [PATCH 1/1] cifs: sanitize multiple delimiters in prepath Leif Sahlberg
2021-12-16 3:14 ` Steve French
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=20211215030831.24058-1-trbecker@gmail.com \
--to=trbecker@gmail.com \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lsahlber@redhat.com \
--cc=sfrench@samba.org \
/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