hahwul/jwt-hack

segmentation violation

hahwul opened this issue · 1 comments

If there is an abnormal input among some functions, error handling is not performed. (by nil)

e.g

 jwt-hack decode abcd                                                                                                                                          10:05:38 오후
   d8p 8d8   d88 888888888          888  888 ,8b.     doooooo 888  ,dP 
   88p 888,o.d88    '88d     ______ 88888888 88'8o    d88     888o8P'  
   88P 888P`Y8b8   '888      XXXXXX 88P  888 88PPY8.  d88     888 Y8L 
88888' 88P   YP8 '88p               88P  888 8b   `Y' d888888 888  `8p
-------------------------
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x5f709b]

goroutine 1 [running]:
github.com/hahwul/jwt-hack/cmd.glob..func2(0x7eb600, 0xc000098920, 0x1, 0x1)
        /home/devi/go/src/github.com/hahwul/jwt-hack/cmd/decode.go:30 +0x17b
jwt-hack encode abcd                                                                                                                                          10:05:42 오후
   d8p 8d8   d88 888888888          888  888 ,8b.     doooooo 888  ,dP 
   88p 888,o.d88    '88d     ______ 88888888 88'8o    d88     888o8P'  
   88P 888P`Y8b8   '888      XXXXXX 88P  888 88PPY8.  d88     888 Y8L 
88888' 88P   YP8 '88p               88P  888 8b   `Y' d888888 888  `8p
-------------------------
ERRO[0000] JSON Unmarshal Error                         
panic: 0

goroutine 1 [running]:
github.com/hahwul/jwt-hack/cmd.glob..func3(0x7eb8a0, 0xc000056950, 0x1, 0x1)
        /home/devi/go/src/github.com/hahwul/jwt-hack/cmd/encode.go:25 +0x45b
github.com/spf13/cobra.(*Command).execute(0x7eb8a0, 0xc000056920, 0x1, 0x1, 0x7eb8a0, 0xc000056920)
        /home/devi/go/src/github.com/spf13/cobra/command.go:854 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x7ebde0, 0x4456ea, 0x7d0e80, 0xc000000180)

Solution: panic() => os.Exit()