diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-09 19:37:14 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-09-22 19:33:24 +0900 |
commit | d23cbd4bc331f8bc0cd8c5e42eb3f5b027410b34 (patch) | |
tree | fd91b26c82216f02be841802b5272749c85cd1e1 | |
parent | 4eda40878fc42ac5bad6dd7b1ebc8f0eac796b94 (diff) | |
download | ruby-openssl-history-d23cbd4bc331f8bc0cd8c5e42eb3f5b027410b34.tar.gz |
asn1: don't use assert() in decode_bool()
The length is not necessary 3. Fixes r55288 (0b1e59f2c11b, "openssl:
avoid d2i_ASN1_BOOLEAN()", 2016-06-05).
-rw-r--r-- | ext/openssl/ossl_asn1.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c index 2a580d6..4f9302e 100644 --- a/ext/openssl/ossl_asn1.c +++ b/ext/openssl/ossl_asn1.c @@ -364,13 +364,12 @@ decode_bool(unsigned char* der, long length) { const unsigned char *p = der; - assert(length == 3); - if (*p++ != 1) - ossl_raise(eASN1Error, "not a boolean"); - if (*p++ != 1) - ossl_raise(eASN1Error, "length is not 1"); + if (length != 3) + ossl_raise(eASN1Error, "invalid length for BOOLEAN"); + if (p[0] != 1 || p[1] != 1) + ossl_raise(eASN1Error, "invalid BOOLEAN"); - return *p ? Qtrue : Qfalse; + return p[2] ? Qtrue : Qfalse; } static VALUE |