Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can named pipe names have backslashes?

According to MSDN,

[The pipe name] must have the following form:

\\.\pipe\pipename

The pipename part of the name can include any character other than a backslash, including numbers and special characters. The entire pipe name string can be up to 256 characters long. Pipe names are not case sensitive.

But there are plenty of examples where I've seen named pipe names with backslashes in them. For example, the standard pipe name for SQL Server is \\.\pipe\sql\query.

Running PipeList from SysInternals reveals plenty of pipes on my machine where the name includes a backslash.

So, can a pipe name have a backslash in it or not?

I ask because I was creating a service with several pipes with names like this:

\\.\pipe\MyApp
\\.\pipe\MyApp\0
\\.\pipe\MyApp\1
\\.\pipe\MyApp\2

After the first pipe was created, creating the other pipes would fail with Windows error 123 (ERROR_INVALID_NAME). If I skipped creating the first pipe, all the others, with the backslash character in the name, would work just fine.

It appears that pipes are hierarchical like the file system, and if you have a pipe with a particular name, that name can no longer be used as a "folder" or container for other pipes.

When trying to figure this out, I came across the MSDN article and am now questioning whether I should be using backslashes at all.

Any advice?

like image 501
GBegen Avatar asked Aug 26 '10 01:08

GBegen


1 Answers

While this appears to be undocumented behavior, it is at least consistent. Just don't create a pipe with the same name as a 'folder'. Windows implements named pipes as a filesystem internally. However also keep in mind that a malicious application could create a \.\pipe\MyApp pipe and cause your app to fail. Considering the only benefits of using the backslash are purely semantic, I would recommend using an underscore or other character instead.

like image 90
adzm Avatar answered Sep 27 '22 22:09

adzm