Re: Fwd: [PATCH] Convert trailing spaces and periods in path components

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



What was the server for these tests?

On 9/29/2020 1:08 PM, Boris Protopopov wrote:
Testing:

Prior to the patch:

% mount -v
…
//host/share/home on /tmp/diry type cifs (rw,relatime,vers=default,...
% ls -l /tmp/diry/tmp
total 0
% mkdir /tmp/diry/tmp/DirWithTrailingDot.
% ls -l  /tmp/diry/tmp/DirWithTrailingDot.
total 0
% touch  /tmp/diry/tmp/DirWithTrailingDot./file
touch: cannot touch ‘/tmp/diry/tmp/DirWithTrailingDot./file’: No such
file or directory
% mkdir  /tmp/diry/tmp/DirWithTrailingDot./dir
mkdir: cannot create directory
‘/tmp/diry/tmp/DirWithTrailingDot./dir’: No such file or directory
% find  /tmp/diry/tmp/DirWithTrailingDot.
/tmp/diry/tmp/DirWithTrailingDot.
% find  /tmp/diry/tmp/DirWithTrailingSpace\
find: `/tmp/diry/tmp/DirWithTrailingSpace ': No such file or directory
% mkdir  /tmp/diry/tmp/DirWithTrailingSpace\
% ls -l  /tmp/diry/tmp/DirWithTrailingSpace\
total 0
% touch /tmp/diry/tmp/DirWithTrailingSpace\ /file
touch: cannot touch ‘/tmp/diry/tmp/DirWithTrailingSpace /file’: No
such file or directory
% mkdir /tmp/diry/tmp/DirWithTrailingSpace\ /dir
mkdir: cannot create directory ‘/tmp/diry/tmp/DirWithTrailingSpace
/dir’: No such file or directory

After the patch:

% umount /tmp/diry
% modprobe -r cifs
# load the fix
% modprobe cifs
% mount -t cifs -o...  //host/share/home /tmp/diry
...
% mkdir /tmp/diry/tmp/DirWithTrailingSpace\ /dir
% touch /tmp/diry/tmp/DirWithTrailingSpace\ /file
% mkdir  /tmp/diry/tmp/DirWithTrailingDot./dir
% touch  /tmp/diry/tmp/DirWithTrailingDot./file
% find  /tmp/diry/tmp/
/tmp/diry/tmp/
/tmp/diry/tmp/DirWithTrailingDot.
/tmp/diry/tmp/DirWithTrailingDot./dir
/tmp/diry/tmp/DirWithTrailingDot./file
/tmp/diry/tmp/DirWithTrailingSpace
/tmp/diry/tmp/DirWithTrailingSpace /dir
/tmp/diry/tmp/DirWithTrailingSpace /file
% rm -rf /tmp/diry/tmp/*
% find  /tmp/diry/tmp/
/tmp/diry/tmp/

---------- Forwarded message ---------
From: Boris Protopopov <pboris@xxxxxxxxxx>
Date: Wed, Sep 23, 2020 at 8:39 PM
Subject: [PATCH] Convert trailing spaces and periods in path components
To:
Cc: <linux-cifs@xxxxxxxxxxxxxxx>, <samba-technical@xxxxxxxxxxxxxxx>,
Boris Protopopov <pboris@xxxxxxxxxx>


When converting trailing spaces and periods in paths, do so
for every component of the path, not just the last component.
If the conversion is not done for every path component, then
subsequent operations in directories with trailing spaces or
periods (e.g. create(), mkdir()) will fail with ENOENT. This
is because on the server, the directory will have a special
symbol in its name, and the client needs to provide the same.

Signed-off-by: Boris Protopopov <pboris@xxxxxxxxxx>
---
  fs/cifs/cifs_unicode.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 498777d859eb..9bd03a231032 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -488,7 +488,13 @@ cifsConvertToUTF16(__le16 *target, const char
*source, int srclen,
                 else if (map_chars == SFM_MAP_UNI_RSVD) {
                         bool end_of_string;

-                       if (i == srclen - 1)
+                       /**
+                        * Remap spaces and periods found at the end of every
+                        * component of the path. The special cases of '.' and
+                        * '..' do not need to be dealt with explicitly because
+                        * they are addressed in namei.c:link_path_walk().
+                        **/
+                       if ((i == srclen - 1) || (source[i+1] == '\\'))
                                 end_of_string = true;
                         else
                                 end_of_string = false;
--
2.18.4





[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux