Skip to content

Commit dc67a6f

Browse files
committed
Update certCompression logic after review
1 parent aee82a2 commit dc67a6f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/crypto/crypto_context.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

src/crypto/crypto_context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#include "memory_tracker.h"
1111
#include "v8.h"
1212

13+
#ifndef OPENSSL_NO_COMP_ALG
1314
#include <vector>
15+
#endif
1416

1517
namespace node {
1618
namespace crypto {

0 commit comments

Comments
 (0)