Skip to content

os/exec: Cannot execute command with argument that has multiple values #67687

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

Closed
KyriakosMilad opened this issue May 29, 2024 · 1 comment
Closed

Comments

@KyriakosMilad
Copy link

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN='/home/kyri/go/bin'
GOCACHE='/home/kyri/.cache/go-build'
GOENV='/home/kyri/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/kyri/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/kyri/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/home/kyri/projs/goopenssl/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2138521302=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I'm trying to execute openssl command using exec.Command:

opensssl x509 -text -noout -certopt=ca_default,no_validity,no_serial,no_subject,no_extensions,no_signame <<< [CERT]

I tried to do it like this

func (c *Certificate) GetSignature() (string, error) {
       // getSignatureCommand = "x509 -text -noout -certopt=ca_default,no_validity,no_serial,no_subject,no_extensions,no_signame"
	argsSlice := strings.Split(getSignatureCommand, " ")

	stderr := &bytes.Buffer{}
	stdout := &bytes.Buffer{}

       // openSSLCommand = "openssl"
	cmd := exec.Command(openSSLCommand, argsSlice...)
	cmd.Stdin = strings.NewReader(c.cert)
	cmd.Stderr = stderr
	cmd.Stdout = stdout
	err := cmd.Run()
	if err != nil || stderr.Len() > 0 {
		return "", fmt.Errorf("failed to execute command: %v: %v", err, stderr.String())
	}

	// remove last \n
	signature := stdout.String()
	signature = strings.TrimRight(signature, "\n")

	return signature, nil
}

I also tried changing the getSignatureCommand to
x509 -text -noout -certopt ca_default,no_validity,no_serial,no_subject,no_extensions,no_signame

And to
x509 -text -noout -certopt ca_default -certopt no_validity -certopt no_serial -certopt no_subject -certopt no_extensions -certopt no_signame

All fail with error: failed to execute command: exit status 1: x509: Use -help for summary.

What am I doing wrong?

What did you see happen?

failed to execute command: exit status 1: x509: Use -help for summary.

What did you expect to see?

Signature Algorithm: sha1WithRSAEncryption
Signature Value:
6d:94:92:e0:e4:a4:f4:65:aa:e3:cc:1b:9f:2a:01:b0:20:cf:
67:5a:58:cf:aa:d9:99:08:07:91:9a:0b:b6:2b:52:9d:f0:e5:
0d:50:cb:66:8c:a6:93:21:36:11:c7:30:98:45:65:43:e1:54:
a5:22:0bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1e:05:
0e:e3:10:01:73:06:5b:98:f5:e8:6d:73:a5:65:8d:3d:48:b0:
21:4a:30:9f:7c:7d:99:d0:e7:c1:cc:22:fa:c4:fc:9c:48:3f:
ff:83:72:98:d0:33:3b:05:69:84:fd:7b:bc:b8:e6:44:96:cf:
58:27:4c:c3:d1:9d:c1:f1:02:f8:3c:11:92:fe:fa:c1:ff:48:
cf:a8:e9:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx:9b:b0:4f:c2:ca:
28:5b:13:c2:1d:c9:79:7a:71:4c:9c:4a:f5:26:60:6d:75:3f:
00:31:57:8f:00:99:ca:93:52:5d:fc:dd:71:76:1b:22:61:4b:
5f:29:f6:77:fd:f0:e5:20:dc:fd:e1:d5:d2:05:a3:3f:96:2c:
d9:cc:d9:87:9c:7b:16:c8:4f:2c:2e:b6:dd:bd:e5:9b:d7:97:
c5:b0:31:19:69:a7:f8:f9:3e:b2:0b:3d:b0:13:68:a1:1d:ee:
e3:86:60:77

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants