tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.2k stars 892 forks source link

tinygo doesn't preserve stdin perms when spawing programs in `tinygo run`. #1287

Open ribasushi opened 4 years ago

ribasushi commented 4 years ago

TLDR Stat on Stdin ( be it a tty, a pipe or a file ) panics

Version tinygo version 0.14.0 darwin/amd64 (using go version go1.14.7 and LLVM version 10.0.0)

Failure

~$ tinygo run tiny.go
panic: runtime error: nil pointer dereference
error: failed to run compiled binary /var/folders/3y/58n01w8x1xz1wv08x6xflq0h0000gn/T/tinygo353964835/main: signal: abort trap

~$ echo foo | tinygo run tiny.go
panic: runtime error: nil pointer dereference
error: failed to run compiled binary /var/folders/3y/58n01w8x1xz1wv08x6xflq0h0000gn/T/tinygo878131135/main: signal: abort trap

~$ <tiny.go tinygo run tiny.go
panic: runtime error: nil pointer dereference
error: failed to run compiled binary /var/folders/3y/58n01w8x1xz1wv08x6xflq0h0000gn/T/tinygo967377983/main: signal: abort trap

Expectation

~$ go run tiny.go 
in perm:        0620

~$ echo foo | go run tiny.go 
in perm:        0660

~$ <tiny.go go run tiny.go 
in perm:        0644

Testcase

package main

import (
    "fmt"
    "os"
)

func main() {
    inStat, _ := os.Stdin.Stat()
    fmt.Printf("in perm:\t0%o\n", inStat.Mode()&07777)
}
codefromthecrypt commented 2 years ago

@ribasushi I noticed this doesn't panic using latest tinygo, though it always seems to report 0666 in tinygo despite go reporting various modes. If you are satisfied with it not panicing can you close this out? Otherwise, mention what's next? Cheers!

dgryski commented 1 year ago

Note that binaries built with tinygo report the permissions correctly. This bug has to do with how tinygo sets up the sub-processes.