jenkins-zh/jenkins-cli

\n in job param name segfaults

yairfrid opened this issue · 3 comments

Describe the bug
A seg fault in job param

To Reproduce

[yair@yairf_lap ~ ]$ jcli job param "test"
Error: not found resources
Usage:
  jcli job param [flags]

Flags:
      --add string           Add parameters into the Pipeline. Example data: [{"name":"name","value":"rick","desc":"this is a name"}]
      --filter stringArray   Filter for the list by fields
  -h, --help                 help for param
      --indent               Output with indent
      --no-headers           When using the default output format, don't print headers (default print headers)
      --remove string        Remove parameters from the Pipeline. Example data: name,age

Global Flags:
      --config-load                 If load a default config file (default true)
      --configFile string           An alternative config file
      --debug                       Print the output into debug.html
      --doctor                      Run the diagnose for current command
      --insecureSkipVerify string   If skip insecure skip verify (default "true")
  -j, --jenkins string              Select a Jenkins server for this time
      --logger-level string         Logger level which could be: debug, info, warn, error (default "warn")
  -o, --output string               Format the output (default "json")
      --proxy string                The proxy of connection to Jenkins
      --proxy-auth string           The auth of proxy of connection to Jenkins
      --proxy-disable               Disable proxy setting
      --timeout int                 Timeout in second setting for http request (default 30)
      --token string                The token of Jenkins
      --url string                  The URL of Jenkins
      --username string             The username of Jenkins

[yair@yairf_lap ~ ]$ jcli job param "test
dquote> "
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5af0d6]

goroutine 1 [running]:
net/url.(*URL).ResolveReference(0xc000139dd0, 0x0, 0x0)
        /opt/hostedtoolcache/go/1.15.8/x64/src/net/url/url.go:1048 +0x36
github.com/jenkins-zh/jenkins-cli/util.URLJoin(0xc000354420, 0x16, 0xc0003547a0, 0x13, 0x7fffe9088936, 0x5, 0x934b07)
        /home/runner/work/jenkins-cli/jenkins-cli/util/url.go:12 +0x107
github.com/jenkins-zh/jenkins-cli/util.URLJoinAsString(0xc000354420, 0x16, 0xc0003547a0, 0x13, 0x10, 0xc0000a5110, 0xc0001741e0, 0xc0001fd8e0)
        /home/runner/work/jenkins-cli/jenkins-cli/util/url.go:20 +0x4d
github.com/jenkins-zh/jenkins-cli/client.(*JenkinsCore).Request(0xc0001fdcd0, 0xd1595f, 0x3, 0xc0003547a0, 0x13, 0x0, 0x0, 0x0, 0xc0003547a0, 0x13, ...)
        /home/runner/work/jenkins-cli/jenkins-cli/client/common.go:248 +0x6a
github.com/jenkins-zh/jenkins-cli/client.(*JenkinsCore).RequestWithData(0xc0001fdcd0, 0xd1595f, 0x3, 0xc0003547a0, 0x13, 0x0, 0x0, 0x0, 0xc8, 0xba4cc0, ...)
        /home/runner/work/jenkins-cli/jenkins-cli/client/common.go:149 +0x8d
github.com/jenkins-zh/jenkins-cli/client.(*JobClient).GetJob(0xc0001fdcd0, 0x7fffe9088936, 0x5, 0xc0b5a0, 0x0, 0xd3ee22)
        /home/runner/work/jenkins-cli/jenkins-cli/client/job.go:198 +0x13e
github.com/jenkins-zh/jenkins-cli/app/cmd.glob..func44(0x12ae080, 0xc000366020, 0x1, 0x1, 0x0, 0x0)
        /home/runner/work/jenkins-cli/jenkins-cli/app/cmd/job_param.go:65 +0x10b
github.com/spf13/cobra.(*Command).execute(0x12ae080, 0xc000366000, 0x1, 0x1, 0x12ae080, 0xc000366000)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:850 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0x12a5aa0, 0x0, 0x0, 0x0)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:895
github.com/jenkins-zh/jenkins-cli/app/cmd.Execute()
        /home/runner/work/jenkins-cli/jenkins-cli/app/cmd/root.go:176 +0x2d
main.main()
        /home/runner/work/jenkins-cli/jenkins-cli/main.go:8 +0x25

Expected behavior
atleast an error message :)

Desktop (please complete the following information):
WSL2-ubuntu18.04, zsh, version 0.0.35

debug logs:

[yair@yairf_lap ~ ]$ jcli job param "test
dquote> " --logger-level debug
{"level":"debug","message":"read config file","path":""}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5af0d6]

goroutine 1 [running]:
net/url.(*URL).ResolveReference(0xc000139e60, 0x0, 0x0)
        /opt/hostedtoolcache/go/1.15.8/x64/src/net/url/url.go:1048 +0x36
github.com/jenkins-zh/jenkins-cli/util.URLJoin(0xc000344580, 0x16, 0xc000344900, 0x13, 0x7fffc588f876, 0x5, 0x934b07)
        /home/runner/work/jenkins-cli/jenkins-cli/util/url.go:12 +0x107
github.com/jenkins-zh/jenkins-cli/util.URLJoinAsString(0xc000344580, 0x16, 0xc000344900, 0x13, 0x10, 0xc0000b3110, 0xc0001741e0, 0xc0001fd8e0)
        /home/runner/work/jenkins-cli/jenkins-cli/util/url.go:20 +0x4d
github.com/jenkins-zh/jenkins-cli/client.(*JenkinsCore).Request(0xc0001fdcd0, 0xd1595f, 0x3, 0xc000344900, 0x13, 0x0, 0x0, 0x0, 0xc000344900, 0x13, ...)
        /home/runner/work/jenkins-cli/jenkins-cli/client/common.go:248 +0x6a
github.com/jenkins-zh/jenkins-cli/client.(*JenkinsCore).RequestWithData(0xc0001fdcd0, 0xd1595f, 0x3, 0xc000344900, 0x13, 0x0, 0x0, 0x0, 0xc8, 0xba4cc0, ...)
        /home/runner/work/jenkins-cli/jenkins-cli/client/common.go:149 +0x8d
github.com/jenkins-zh/jenkins-cli/client.(*JobClient).GetJob(0xc0001fdcd0, 0x7fffc588f876, 0x5, 0xc0b5a0, 0x0, 0xd3ee22)
        /home/runner/work/jenkins-cli/jenkins-cli/client/job.go:198 +0x13e
github.com/jenkins-zh/jenkins-cli/app/cmd.glob..func44(0x12ae080, 0xc000349980, 0x1, 0x3, 0x0, 0x0)
        /home/runner/work/jenkins-cli/jenkins-cli/app/cmd/job_param.go:65 +0x10b
github.com/spf13/cobra.(*Command).execute(0x12ae080, 0xc000349950, 0x3, 0x3, 0x12ae080, 0xc000349950)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:850 +0x47c
github.com/spf13/cobra.(*Command).ExecuteC(0x12a5aa0, 0x0, 0x0, 0x0)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:895
github.com/jenkins-zh/jenkins-cli/app/cmd.Execute()
        /home/runner/work/jenkins-cli/jenkins-cli/app/cmd/root.go:176 +0x2d
main.main()
        /home/runner/work/jenkins-cli/jenkins-cli/main.go:8 +0x25
yJunS commented

@Fongeme Thanks for your reporting. I will try my best to dig it once I have free time.

yJunS commented

Hi, @Fongeme I fix the question, you should try that if you have free time.