URL not correctly parsed if password contains number sign ('#')

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

URL not correctly parsed if password contains number sign ('#')

Guertler Mario

Hi all,

 

I think I found a bug in your implementation. We are using JCIFS in many applications successfully, but if the number sign (‘#’) is used in password then we get problems.

I already figured out where the problem is; the passed URL string of constructor ‘public SmbFile(String url)’ is not correctly parsed.

 

The following code:

 

String connectString ="smb://user:passwort#123456789@host/share/Test/”;

SmbFile polledFile = new SmbFile(connectString);

 

Results in following field variables of class SmbFile or better of class URL

 

authority             "user:test#123456789@host"

file                         "#123456789@host/share/Test/"

path                      "#123456789@host/share/Test/"

protocol              "smb"

userInfo              "user:test#123456789"

 

So you can see that the file/path is not correct und the access to this file will fail because it does not exist.

 

Mit freundlichem Gruß / Best regards

 

Mario Gürtler

Senior Engineer

 

znt Zentren für Neue Technologien GmbH
Institut Dresden
Am Brauhaus 12
D-01099 Dresden

 

Hauptverwaltung und Sitz: Lena-Christ-Str. 2, 82031 Grünwald, Amtsgericht München HRB 179019
Geschäftsführer: Bernhard Marsoner, Ulrike Birnstiel
Prokuristen: Hans Mayer, Gerhard Schrottshamer

 

Office:   +49 351 652 480-20
Mobile: 
Fax:      +49 351 652 480-29
E-Mail:   [hidden email]
Web:    
http://www.znt-richter.com

 

http://www.znt-richter.com/mlogos/logo.jpg
Munich | Burghausen | Dresden | Villach/Austria | Singapore | Penang/Malaysia | San Francisco/USA

 

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

 

Reply | Threaded
Open this post in threaded view
|

Re: URL not correctly parsed if password contains number sign ('#')

Michael B Allen
On Thu, Feb 4, 2016 at 9:12 AM, Guertler Mario <[hidden email]> wrote:

Hi all,

 

I think I found a bug in your implementation. We are using JCIFS in many applications successfully, but if the number sign (‘#’) is used in password then we get problems.

I already figured out where the problem is; the passed URL string of constructor ‘public SmbFile(String url)’ is not correctly parsed.

 

The following code:

 

String connectString ="smb://user:passwort#123456789@host/share/Test/”;

SmbFile polledFile = new SmbFile(connectString);

 

Results in following field variables of class SmbFile or better of class URL

 

authority             "user:test#123456789@host"

file                         "#123456789@host/share/Test/"

path                      "#123456789@host/share/Test/"

protocol              "smb"

userInfo              "user:test#123456789"

 

So you can see that the file/path is not correct und the access to this file will fail because it does not exist.


Hi Mario,

This is actually not a bug. You must URL encode any characters in a URL that are special characters for URLs. The # sign is a ref marker. Try substituting with %23.

However, you should not put the password in the URL in the first place. That is only for quick and dirty things like running something once from a commandline. The correct way to pass credentials is to create an NtlmPasswordAuthentication object and use that with the appropriate constructor.

Mike