spacemonkeygo / openssl

OpenSSL bindings for Go
http://godoc.org/github.com/spacemonkeygo/openssl
Apache License 2.0
473 stars 236 forks source link

EncryptUpdate panics on empty input #95

Closed rameshrv closed 5 years ago

rameshrv commented 6 years ago

I am using the openssl library to encrypt/decrypt data.

I have a Unit test to encrypt/decrypt empty data ( like: []byte("") ). It causes a panic as follows:

--- FAIL: TestEmptyEncryption (0.00s)
panic: runtime error: index out of range [recovered]
    panic: runtime error: index out of range

goroutine 7 [running]:
testing.tRunner.func1(0xc42015c0f0)
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:711 +0x2d2
panic(0x434b140, 0x45959f0)
    /usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
goef/vendor/github.com/spacemonkeygo/openssl.(*encryptionCipherCtx).EncryptUpdate(0xc42000e0b0, 0x45bf568, 0x0, 0x0, 0x20, 0xc4200146b0, 0x10, 0x10, 0x456b9a0)
    /Users/rarayapr/go-workspace/src/goef/vendor/github.com/spacemonkeygo/openssl/ciphers.go:285 +0x21a
goef/pac.(*CryptObject).EncryptData(0xc42005e940, 0x45bf568, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x407ce96)
    /Users/rarayapr/go-workspace/src/goef/pac/cipher.go:61 +0xe0
goef/pac.TestEmptyEncryption(0xc42015c0f0)
    /Users/rarayapr/go-workspace/src/goef/pac/cipher_test.go:98 +0x150
testing.tRunner(0xc42015c0f0, 0x43c45f0)
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:746 +0xd0
created by testing.(*T).Run
    /usr/local/Cellar/go/1.9.2/libexec/src/testing/testing.go:789 +0x2de
exit status 2
zeebo commented 6 years ago

Oh, wow. A panic is surely no good. Thanks for the report, but I’ll be away for ~2 weeks, so I may not get to it.

rameshrv commented 6 years ago

Hi @zeebo , no worries. It was not blocking me anyways because its a negative test case. I can wait on it. Thank you!