Skip to content

Commit 839db3d

Browse files
jtlaytonsmfrench
authored andcommitted
cifs: fix up handling of prefixpath= option
Currently the code takes care to ensure that the prefixpath has a leading '/' delimiter. What if someone passes us a prefixpath with a leading '\\' instead? The code doesn't properly handle that currently AFAICS. Let's just change the code to skip over any leading delimiter character when copying the prepath. Then, fix up the users of the prepath option to prefix it with the correct delimiter when they use it. Also, there's no need to limit the length of the prefixpath to 1k. If the server can handle it, why bother forbidding it? Pavel Shilovsky <piastry@etersoft.ru> Signed-off-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com>
1 parent 62a1a43 commit 839db3d

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

‎fs/cifs/connect.c‎

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,31 +1612,14 @@ cifs_parse_mount_options(const char *mountdata, const char *devname,
16121612
}
16131613
break;
16141614
case Opt_prefixpath:
1615-
string = match_strdup(args);
1616-
if (string == NULL)
1617-
goto out_nomem;
1618-
1619-
temp_len = strnlen(string, 1024);
1620-
if (string[0] != '/')
1621-
temp_len++; /* missing leading slash */
1622-
if (temp_len > 1024) {
1623-
printk(KERN_WARNING "CIFS: prefix too long\n");
1624-
goto cifs_parse_mount_err;
1625-
}
1626-
1627-
vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1628-
if (vol->prepath == NULL) {
1629-
printk(KERN_WARNING "CIFS: no memory "
1630-
"for path prefix\n");
1631-
goto cifs_parse_mount_err;
1632-
}
1633-
1634-
if (string[0] != '/') {
1635-
vol->prepath[0] = '/';
1636-
strcpy(vol->prepath+1, string);
1637-
} else
1638-
strcpy(vol->prepath, string);
1615+
/* skip over any leading delimiter */
1616+
if (*args[0].from == '/' || *args[0].from == '\\')
1617+
args[0].from++;
16391618

1619+
kfree(vol->prepath);
1620+
vol->prepath = match_strdup(args);
1621+
if (vol->prepath == NULL)
1622+
goto out_nomem;
16401623
break;
16411624
case Opt_iocharset:
16421625
string = match_strdup(args);
@@ -3236,7 +3219,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
32363219
const struct cifs_sb_info *cifs_sb)
32373220
{
32383221
char *full_path, *pos;
3239-
unsigned int pplen = vol->prepath ? strlen(vol->prepath) : 0;
3222+
unsigned int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
32403223
unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
32413224

32423225
full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
@@ -3247,6 +3230,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
32473230
pos = full_path + unc_len;
32483231

32493232
if (pplen) {
3233+
*pos++ = CIFS_DIR_SEP(cifs_sb);
32503234
strncpy(pos, vol->prepath, pplen);
32513235
pos += pplen;
32523236
}

‎fs/cifs/dir.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ char *
4848
cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
4949
struct cifs_tcon *tcon)
5050
{
51-
int pplen = vol->prepath ? strlen(vol->prepath) : 0;
51+
int pplen = vol->prepath ? strlen(vol->prepath) + 1 : 0;
5252
int dfsplen;
5353
char *full_path = NULL;
5454

@@ -69,7 +69,8 @@ cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
6969

7070
if (dfsplen)
7171
strncpy(full_path, tcon->treeName, dfsplen);
72-
strncpy(full_path + dfsplen, vol->prepath, pplen);
72+
full_path[dfsplen] = CIFS_DIR_SEP(cifs_sb);
73+
strncpy(full_path + dfsplen + 1, vol->prepath, pplen);
7374
convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
7475
full_path[dfsplen + pplen] = 0; /* add trailing null */
7576
return full_path;

0 commit comments

Comments
 (0)