GeezerVison is showing github.com — crypto: fix handling of null BUF_MEM* in ToV8Value() · nodejs/node@dc384f9
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_keys.cc +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -86,8 +86,15 @@ MaybeLocal<Value> ToV8Value( |
86 | 86 | Environment* env, |
87 | 87 | const BIOPointer& bio, |
88 | 88 | const EVPKeyPointer::AsymmetricKeyEncodingConfig& config) { |
89 | | - if (!bio) return {}; |
| 89 | + if (!bio) { |
| 90 | + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Invalid BIO pointer"); |
| 91 | + return {}; |
| 92 | + } |
90 | 93 | BUF_MEM* bptr = bio; |
| 94 | + if (!bptr) { |
| 95 | + THROW_ERR_CRYPTO_OPERATION_FAILED(env, "Unable to create BUF_MEM pointer"); |
| 96 | + return {}; |
| 97 | + } |
91 | 98 | if (config.format == EVPKeyPointer::PKFormatType::PEM) { |
92 | 99 | // PEM is an ASCII format, so we will return it as a string. |
93 | 100 | return String::NewFromUtf8( |
|
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_x509.cc +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,6 +106,8 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, BIOPointer&& bio) { |
106 | 106 | if (!bio) [[unlikely]] |
107 | 107 | return {}; |
108 | 108 | BUF_MEM* mem = bio; |
| 109 | + if (!mem) [[unlikely]] |
| 110 | + return {}; |
109 | 111 | Local<Value> ret; |
110 | 112 | if (!String::NewFromUtf8(Isolate::GetCurrent(), |
111 | 113 | mem->data, |
@@ -120,6 +122,8 @@ MaybeLocal<Value> ToV8Value(Local<Context> context, const BIOPointer& bio) { |
120 | 122 | if (!bio) [[unlikely]] |
121 | 123 | return {}; |
122 | 124 | BUF_MEM* mem = bio; |
| 125 | + if (!mem) [[unlikely]] |
| 126 | + return {}; |
123 | 127 | Local<Value> ret; |
124 | 128 | if (!String::NewFromUtf8(Isolate::GetCurrent(), |
125 | 129 | mem->data, |
@@ -134,6 +138,8 @@ MaybeLocal<Value> ToBuffer(Environment* env, BIOPointer* bio) { |
134 | 138 | if (bio == nullptr || !*bio) [[unlikely]] |
135 | 139 | return {}; |
136 | 140 | BUF_MEM* mem = *bio; |
| 141 | + if (!mem) [[unlikely]] |
| 142 | + return {}; |
137 | 143 | #ifdef V8_ENABLE_SANDBOX |
138 | 144 | // If the v8 sandbox is enabled, then all array buffers must be allocated |
139 | 145 | // via the isolate. External buffers are not allowed. So, instead of wrapping |
|