Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: Windows named pipes are listed as regular by Stat #41755

Open
secDre4mer opened this issue Oct 2, 2020 · 6 comments
Open

os: Windows named pipes are listed as regular by Stat #41755

secDre4mer opened this issue Oct 2, 2020 · 6 comments
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@secDre4mer
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.15.2 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Max\AppData\Local\go-build
set GOENV=C:\Users\Max\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Max\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Max\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Max\AppData\Local\Temp\go-build300293506=/tmp/go-build -gno-record-gcc-switches

The underlying OS is Windows 10, version 2004.

What did you do?

I ran os.Stat, passing an existing pipe as an example. Source code for this can be found at https://play.golang.org/p/a1O5axVpLOO
In this example, the Pipe is created in the Golang program, but the issue is also reproducible when using a different, existing pipe.

What did you expect to see?

The FileInfo should have ModeNamedPipe set.

What did you see instead?

The FileInfo had no ModeNamedPipe set and was listed as a regular file.
Output from the example code:

$ go run .
0
438
true
@ianlancetaylor ianlancetaylor changed the title Windows Named Pipes are listed as regular by os.Stat os: Windows named pipes are listed as regular by Stat Oct 2, 2020
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Oct 2, 2020
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Oct 2, 2020
@ianlancetaylor
Copy link
Contributor

CC @alexbrainman

@networkimprov
Copy link

cc @iwdgo @mattn

@mattn
Copy link
Member

mattn commented Oct 3, 2020

When calling os.Stat(\\.\pipe\somepipe), fileStat is returned from result of GetFileAttributesEx

// Not a symlink.
fs := &fileStat{
FileAttributes: fa.FileAttributes,
CreationTime: fa.CreationTime,
LastAccessTime: fa.LastAccessTime,
LastWriteTime: fa.LastWriteTime,
FileSizeHigh: fa.FileSizeHigh,
FileSizeLow: fa.FileSizeLow,
}
if err := fs.saveInfoFromPath(name); err != nil {
return nil, err
}
return fs, nil

So the filetype field that is used by FileInfo.Mode() always become 0. To get filetype, it should call GetFileInformationByHandle, but that named pipe can not be called CreateFile since the pipe is not connected yet by ConnectNamedPipe. CreateFile retrurn ERROR_PIPE_BUSY until ConnectNamedPipe is called.

Most easy way to detect that the path is pipe is checking the path start with \.\pipe. but this is ugly.

@alexbrainman
Copy link
Member

Same as @mattn . I do not know how to determine if opened file is named pipe or not.

Alex

@gopherbot
Copy link

Change https://golang.org/cl/373354 mentions this issue: os: set file mode for pipes on windows

@bcmills
Copy link
Contributor

bcmills commented Oct 12, 2023

(CC @golang/windows)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

7 participants