Skip to content

etcd CLI command will be panic if the parameter is invalid #11958

Closed
@microyahoo

Description

@microyahoo
Contributor

Reproduce Procedure

The panic is as follows:

(ENV) 🍺 /Users/go/src/github.com/etcd-io/etcd ☞ git:(test) βœ— ./bin/etcd version
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x135b7ce]

goroutine 1 [running]:
go.uber.org/zap.(*Logger).check(0x0, 0x1, 0x1c5d90a, 0x16, 0xc000091800)
	/Users/go/src/github.com/etcd-io/etcd/vendor/go.uber.org/zap/logger.go:263 +0x90e
go.uber.org/zap.(*Logger).Warn(0x0, 0x1c5d90a, 0x16, 0xc000091800, 0x1, 0x1)
	/Users/go/src/github.com/etcd-io/etcd/vendor/go.uber.org/zap/logger.go:194 +0x44
go.etcd.io/etcd/v3/etcdmain.startEtcdOrProxyV2()
	/Users/go/src/github.com/etcd-io/etcd/etcdmain/etcd.go:61 +0x327
go.etcd.io/etcd/v3/etcdmain.Main()
	/Users/go/src/github.com/etcd-io/etcd/etcdmain/main.go:46 +0x37
main.main()
	/Users/go/src/github.com/etcd-io/etcd/main.go:28 +0x20

What are we using?

(ENV) ➜ /Users/go/src/github.com/etcd-io/etcd ☞ git:(test) βœ— ./bin/etcd --version
etcd Version: 3.5.0-pre
Git SHA: 9b6c3e337
Go Version: go1.14.3
Go OS/Arch: darwin/amd64

Analysis

The root cause is lg will be nil in line 61 if config parsing returns a error in the file of etcdmain/etcd.go, because lg will be initialized during the configFromCmdLine().

 52 func startEtcdOrProxyV2() {
 53     grpc.EnableTracing = false
 54
 55     cfg := newConfig()
 56     defaultInitialCluster := cfg.ec.InitialCluster
 57
 58     err := cfg.parse(os.Args[1:])
 59     lg := cfg.ec.GetLogger()
 60     if err != nil {
 61         lg.Warn("failed to verify flags", zap.Error(err))
 62         switch err {
 63         case embed.ErrUnsetAdvertiseClientURLsFlag:
 64             lg.Warn("advertise client URLs are not set", zap.Error(err))
 65         }
 66         os.Exit(1)
 67     }

Activity

microyahoo

microyahoo commented on Jun 15, 2020

@microyahoo
ContributorAuthor

I have noticed this issue was introduced with PR 0a05f1a. Will the package github.com/coreos/pkg/capnslog be removed permanently? @jingyih

spzala

spzala commented on Jun 15, 2020

@spzala
Member

I have noticed this issue was introduced with PR 0a05f1a. Will the package github.com/coreos/pkg/capnslog be removed permanently? @jingyih

@microyahoo yes, and the issue is now fixed under #11962

spzala

spzala commented on Jun 15, 2020

@spzala
Member

I am closing it @microyahoo Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @spzala@microyahoo

        Issue actions

          etcd CLI command will be panic if the parameter is invalid Β· Issue #11958 Β· etcd-io/etcd