diff mbox

Convert slashes in the UNC parameter to backslashes

Message ID 509902BB.6020400@innominate.com (mailing list archive)
State New, archived
Headers show

Commit Message

Federico Sauter Nov. 6, 2012, 12:29 p.m. UTC
This patch ensures that slashes used as separators in the
UNC are properly converted to backslashes. The existing
implementation did not perform that conversion and that
lead to a "invalid argument" error when specifying an UNC
explicitly which contained slashes in it.

---
  fs/cifs/connect.c |   12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)

  	separator[1] = 0;
@@ -1573,12 +1574,11 @@ cifs_parse_mount_options(const char *mountdata, 
const char *devname,
  				printk(KERN_WARNING "CIFS: no memory for UNC\n");
  				goto cifs_parse_mount_err;
  			}
-			strcpy(vol->UNC, string);
-
-			if (strncmp(string, "//", 2) == 0) {
-				vol->UNC[0] = '\\';
-				vol->UNC[1] = '\\';
-			} else if (strncmp(string, "\\\\", 2) != 0) {
+			for (p = string, q = vol->UNC; *p; ++p, ++q) {
+				*q = *p == '/'? '\\' : *p;
+			}
+			*q = '\0';
+			if (strncmp(vol->UNC, "\\\\", 2) != 0) {
  				printk(KERN_WARNING "CIFS: UNC Path does not "
  						    "begin with // or \\\\\n");
  				goto cifs_parse_mount_err;

Comments

Jeff Layton Nov. 7, 2012, 12:02 p.m. UTC | #1
On Tue, 06 Nov 2012 13:29:47 +0100
Federico Sauter <fsauter@innominate.com> wrote:

> This patch ensures that slashes used as separators in the
> UNC are properly converted to backslashes. The existing
> implementation did not perform that conversion and that
> lead to a "invalid argument" error when specifying an UNC
> explicitly which contained slashes in it.
> 
> ---
>   fs/cifs/connect.c |   12 ++++++------
>   1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> index 5c670b9..8f4c76f 100644
> --- a/fs/cifs/connect.c
> +++ b/fs/cifs/connect.c
> @@ -1108,6 +1108,7 @@ cifs_parse_mount_options(const char *mountdata, 
> const char *devname,
>   	char *string = NULL;
>   	char *tmp_end, *value;
>   	char delim;
> +	char *p, *q;
> 
>   	separator[0] = ',';
>   	separator[1] = 0;
> @@ -1573,12 +1574,11 @@ cifs_parse_mount_options(const char *mountdata, 
> const char *devname,
>   				printk(KERN_WARNING "CIFS: no memory for UNC\n");
>   				goto cifs_parse_mount_err;
>   			}
> -			strcpy(vol->UNC, string);
> -
> -			if (strncmp(string, "//", 2) == 0) {
> -				vol->UNC[0] = '\\';
> -				vol->UNC[1] = '\\';
> -			} else if (strncmp(string, "\\\\", 2) != 0) {
> +			for (p = string, q = vol->UNC; *p; ++p, ++q) {
> +				*q = *p == '/'? '\\' : *p;
> +			}
> +			*q = '\0';
> +			if (strncmp(vol->UNC, "\\\\", 2) != 0) { 
>   				printk(KERN_WARNING "CIFS: UNC Path does not "
>   						    "begin with // or \\\\\n");
>   				goto cifs_parse_mount_err;



Looks harmless enough, but it would be clearer to use the
convert_delimiter() helper function here, rather than open-coding that
functionality.

Long term, it would be good to get rid of the unc= and prefixpath=
options altogether and simply have the kernel extract this information
from the device name at mount time instead.
diff mbox

Patch

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 5c670b9..8f4c76f 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1108,6 +1108,7 @@  cifs_parse_mount_options(const char *mountdata, 
const char *devname,
  	char *string = NULL;
  	char *tmp_end, *value;
  	char delim;
+	char *p, *q;

  	separator[0] = ',';