namecoin/pkcs11mod

pkcs11proxy triggers a Go panic if the target module isn't found

Closed this issue · 0 comments

If pkcs11proxy is built with a target module path that doesn't exist, it will cause a Go panic:

pkcs11proxy changed line:

backend := pkcs11.New("/usr/lib64/pkcs11/p11-kit-trustX.so") // This path does not exist

Result:

$ /usr/lib64/nss/unsupported-tools/tstclnt -R ./libmypkcs11module.so  -D -h www.namecoin.org

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fffbc461d68]

goroutine 17 [running, locked to thread]:
github.com/miekg/pkcs11.(*Ctx).Initialize.func1(0x0, 0x7fffbc3c191c)
	/home/user/go/pkg/mod/github.com/miekg/pkcs11@v1.0.3/pkcs11.go:805 +0x38
github.com/miekg/pkcs11.(*Ctx).Initialize(0x0, 0x1, 0x7fffbc540001)
	/home/user/go/pkg/mod/github.com/miekg/pkcs11@v1.0.3/pkcs11.go:805 +0x40
github.com/namecoin/pkcs11mod.Go_Initialize(...)
	/home/user/Downloads/pkcs11mod/pkcs11mod.go:68
Aborted (core dumped)

Obviously a nil backend isn't expected to do anything useful, but pkcs11mod should handle this more gracefully than panicking; the application may be able to cope with an erroring PKCS#11 module as long as the module doesn't panic.