@@ -2090,25 +2090,30 @@ void SecureContext::SetCertificateCompression(
20902090 Local<Array> arr = args[0 ].As <Array>();
20912091 uint32_t len = arr->Length ();
20922092
2093- if (len == 0 || len > TLSEXT_comp_cert_limit) {
2093+ // TLSEXT_comp_cert_limit is the limit for a zero-terminated algs array,
2094+ // total number of available algs is one fewer.
2095+ constexpr uint32_t kMaxCompAlgs = TLSEXT_comp_cert_limit - 1 ;
2096+ if (len == 0 || len > kMaxCompAlgs ) {
20942097 return THROW_ERR_INVALID_ARG_VALUE (
2095- env, " certificateCompression must contain 1 to 3 algorithm names" );
2098+ env,
2099+ " certificateCompression must specify fewer than %d algorithms" ,
2100+ kMaxCompAlgs );
20962101 }
20972102
20982103#ifndef OPENSSL_NO_COMP_ALG
2099- int algs[TLSEXT_comp_cert_limit ];
2104+ int algs[kMaxCompAlgs ];
21002105 for (uint32_t i = 0 ; i < len; i++) {
21012106 Local<Value> val;
21022107 if (!arr->Get (env->context (), i).ToLocal (&val) || !val->IsString ()) {
21032108 return THROW_ERR_INVALID_ARG_VALUE (
21042109 env, " certificateCompression entries must be strings" );
21052110 }
21062111 Utf8Value name (env->isolate (), val);
2107- if (strcmp (* name, " zlib " ) == 0 ) {
2112+ if (name. ToStringView ( ) == " zlib " ) {
21082113 algs[i] = TLSEXT_comp_cert_zlib;
2109- } else if (strcmp (* name, " brotli " ) == 0 ) {
2114+ } else if (name. ToStringView ( ) == " brotli " ) {
21102115 algs[i] = TLSEXT_comp_cert_brotli;
2111- } else if (strcmp (* name, " zstd " ) == 0 ) {
2116+ } else if (name. ToStringView ( ) == " zstd " ) {
21122117 algs[i] = TLSEXT_comp_cert_zstd;
21132118 } else {
21142119 return THROW_ERR_INVALID_ARG_VALUE (
0 commit comments