Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Allow . as hostname in pipe names#17284

Merged
saurabh500 merged 3 commits into
dotnet:masterfrom
saurabh500:fixDotAsHost
Mar 21, 2017
Merged

Allow . as hostname in pipe names#17284
saurabh500 merged 3 commits into
dotnet:masterfrom
saurabh500:fixDotAsHost

Conversation

@saurabh500
Copy link
Copy Markdown
Contributor

Fixes https://github.com/dotnet/corefx/issues/17282

Since Uri cannot handle . as hostname, the changes include splitting the named pipe data source by \ and generating the hostname and pipename from the split parts.

Apart from the tests added, I ran some tests with a SqlServer to see if the connectivity works.

cc @corivera @geleems

@saurabh500 saurabh500 added this to the 2.0.0 milestone Mar 20, 2017
}

string[] absolutePathParts = uri.AbsolutePath.Split(ForwardSlashSeparator);
string host = tokensByBackSlash[2];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do string host = tokensByBackSlash[2].Trim();?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Np:\.\pipe\sql\query would lead to a successful connection but np:\. \pipe\sql\query doesn't lead to a successful connection in Native SNI.
We shouldnt trim the pipe parts.

// Another valid Sql named pipe for an named instance is \\.\pipe\MSSQL$MYINSTANCE\sql\query
if (absolutePathParts.Length < 4)
//Check if the "pipe" keyword is the first part of path
if (!PipeToken.Equals(tokensByBackSlash[3]))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if (!PipeToken.Equals(tokensByBackSlash[3].Trim()))?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No trimming of pipe paths.


for ( int i = 4; i < tokensByBackSlash.Length-1; i++)
{
pipeNameBuilder.Append(tokensByBackSlash[i]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do pipeNameBuilder.Append(tokensByBackSlash[i].Trim()); ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

pipeNameBuilder.Append(Path.PathSeparator);
}
// Append the last part without a "/"
pipeNameBuilder.Append(tokensByBackSlash[tokensByBackSlash.Length - 1]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if connection string is \\.\pipe\sql\query\ ?

Copy link
Copy Markdown
Contributor Author

@saurabh500 saurabh500 Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SqlClient should fail to connect in this case.
With the change above a blank will be appended after the last \ and there will be a failure to connect

ReportSNIError(SNIProviders.NP_PROV);
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for leading backslashes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard this, there's a check for it higher up.

@saurabh500 saurabh500 merged commit 6efbe44 into dotnet:master Mar 21, 2017
@saurabh500 saurabh500 deleted the fixDotAsHost branch May 2, 2017 22:00
dotnet-bot pushed a commit that referenced this pull request Mar 30, 2018
* Use ROSpan.IndexOf as the workhorse for string.IndexOf

* Make changes to Span.IndexOf to follow what string.IndexOf did.

* Address PR feedback.

* Use Unsafe.Read instead of Unsafe.ReadUnaligned.

* Remove special casing for count == 0

* Fix up debug assert to use vector count instead of intptr.size

* Use size of Vector<ushort> instead of Vector<byte>.Count

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
dotnet-bot pushed a commit that referenced this pull request Mar 30, 2018
* Use ROSpan.IndexOf as the workhorse for string.IndexOf

* Make changes to Span.IndexOf to follow what string.IndexOf did.

* Address PR feedback.

* Use Unsafe.Read instead of Unsafe.ReadUnaligned.

* Remove special casing for count == 0

* Fix up debug assert to use vector count instead of intptr.size

* Use size of Vector<ushort> instead of Vector<byte>.Count

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
dotnet-bot pushed a commit that referenced this pull request Mar 30, 2018
* Use ROSpan.IndexOf as the workhorse for string.IndexOf

* Make changes to Span.IndexOf to follow what string.IndexOf did.

* Address PR feedback.

* Use Unsafe.Read instead of Unsafe.ReadUnaligned.

* Remove special casing for count == 0

* Fix up debug assert to use vector count instead of intptr.size

* Use size of Vector<ushort> instead of Vector<byte>.Count

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
dotnet-bot pushed a commit that referenced this pull request Mar 30, 2018
* Use ROSpan.IndexOf as the workhorse for string.IndexOf

* Make changes to Span.IndexOf to follow what string.IndexOf did.

* Address PR feedback.

* Use Unsafe.Read instead of Unsafe.ReadUnaligned.

* Remove special casing for count == 0

* Fix up debug assert to use vector count instead of intptr.size

* Use size of Vector<ushort> instead of Vector<byte>.Count

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
ahsonkhan pushed a commit that referenced this pull request Mar 30, 2018
* Use ROSpan.IndexOf as the workhorse for string.IndexOf

* Make changes to Span.IndexOf to follow what string.IndexOf did.

* Address PR feedback.

* Use Unsafe.Read instead of Unsafe.ReadUnaligned.

* Remove special casing for count == 0

* Fix up debug assert to use vector count instead of intptr.size

* Use size of Vector<ushort> instead of Vector<byte>.Count

Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants